import streamlit as st
import streamlit.components.v1 as components
-__version__ = '0.0.2'
+__version__ = '0.1.0'
st.set_page_config(
page_title='Wayback Tweets',
</style>
'''
-#st.markdown(hide_streamlit_style, unsafe_allow_html=True)
+st.markdown(hide_streamlit_style, unsafe_allow_html=True)
if 'current_index' not in st.session_state:
st.session_state.current_index = 0
if 'current_handle' not in st.session_state:
st.session_state.current_handle = ''
-if 'disabled_next' not in st.session_state:
- st.session_state.disabled_next = False
+if 'prev_disabled' not in st.session_state:
+ st.session_state.prev_disabled = False
-if 'disabled_prev' not in st.session_state:
- st.session_state.disabled_prev = False
+if 'next_disabled' not in st.session_state:
+ st.session_state.next_disabled = False
-def scroll_into_view():
- js = '''
- <script>
- window.parent.document.getElementById('wayback-tweets').scrollIntoView();
- </script>
- '''
+if 'next_button' not in st.session_state:
+ st.session_state.next_button = False
- st.components.v1.html(js)
+if 'prev_button' not in st.session_state:
+ st.session_state.prev_button = False
def embed(tweet):
api = 'https://publish.twitter.com/oembed?url={}'.format(tweet)
tweet_links = []
parsed_mimetype = []
-
for link in links[1:]:
url = 'https://web.archive.org/web/{}/{}'.format(link[1], link[2])
{}. **Wayback Machine:** [link]({}) | **MIME Type:** {} | **From:** {} | **Tweet:** [link]({})
'''.format(i+1, link, mimetype[i], datetime.datetime.strptime(timestamp[i], "%Y%m%d%H%M%S"), tweet_links[i]))
-st.title('Wayback Tweets [](https://github.com/claromes/waybacktweets)', anchor=False)
+st.title('Wayback Tweets [](https://github.com/claromes/waybacktweets/releases)', anchor=False)
st.write('Archived tweets on Wayback Machine')
handle = st.text_input('username', placeholder='username', label_visibility='collapsed')
query = st.button('Query', type='primary', use_container_width=True)
-
-
if query or handle:
if handle != st.session_state.current_handle:
st.session_state.current_index = 0
st.session_state.current_query = query
return_none_count = 0
- tweets_per_page = 2
+ tweets_per_page = 50
+
+ def prev_page():
+ st.session_state.current_index -= tweets_per_page
+
+ def next_page():
+ st.session_state.current_index += tweets_per_page
start_index = st.session_state.current_index
end_index = min(len(parsed_links), start_index + tweets_per_page)
progress.write('{}/{}-{} URLs have been captured'.format(return_none_count, start_index, end_index))
- if start_index == 0:
- st.session_state.disabled_prev = True
+ if start_index <= 0:
+ st.session_state.prev_disabled = True
else:
- st.session_state.disabled_prev = False
+ st.session_state.prev_disabled = False
if i + 1 == len(parsed_links):
- st.session_state.disabled_next = True
+ st.session_state.next_disabled = True
else:
- st.session_state.disabled_next = False
-
- print(start_index, end_index)
+ st.session_state.next_disabled = False
prev, _ , next = st.columns([3, 4, 3])
- if prev.button('Previous', disabled=st.session_state.disabled_prev, type='primary', use_container_width=True):
- scroll_into_view()
- st.session_state.current_index -= tweets_per_page
-
- if next.button('Next', disabled=st.session_state.disabled_next, type='primary', use_container_width=True):
- scroll_into_view()
- st.session_state.current_index += tweets_per_page
-
- # if st.session_state.current_index >= len(parsed_links):
- # st.session_state.current_index = 0
+ prev.button('Previous', disabled=st.session_state.prev_disabled, key='prev_button_key', on_click=prev_page, type='primary', use_container_width=True)
+ next.button('Next', disabled=st.session_state.next_disabled, key='next_button_key', on_click=next_page, type='primary', use_container_width=True)
if not links:
st.error('Unable to query the Wayback Machine API.')