add warning for non 200/300 status code and fixed tweets per page
authorClaromes <claromes@hey.com>
Wed, 13 Dec 2023 16:49:02 +0000 (13:49 -0300)
committerClaromes <claromes@hey.com>
Wed, 13 Dec 2023 16:49:02 +0000 (13:49 -0300)
README.md
app.py

index 141a54f11d6662955274c9545171e6488b230ac5..89a708c0dafcfde7f0b5b9d6e6dc71dcebc54707 100644 (file)
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
 
 Tool that displays, via [Wayback CDX Server API](https://github.com/internetarchive/wayback/tree/master/wayback-cdx-server), multiple archived tweets on Wayback Machine to avoid opening each link manually. The app is a prototype written in Python with Streamlit and hosted at Streamlit Cloud with an extra 7 GiB provided free of charge by the Streamlit team (special thanks to Jessica Smith).
 
-Users can define the number of tweets displayed per page and apply filters based on specific years. Additionally, users can filter and view tweets that lack the original URL.
+Users can apply filters based on specific years and view tweets that lack the original URL.
 
 *Thanks Tristan Lee for the idea.*
 
diff --git a/app.py b/app.py
index 45e53a55b3e3aa3d502283b4116af126deb67ef8..4201665ec21f0743b3e70908ea48eacf204356ef 100644 (file)
--- a/app.py
+++ b/app.py
@@ -19,7 +19,7 @@ st.set_page_config(
 
         [![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/claromes/waybacktweets?include_prereleases)](https://github.com/claromes/waybacktweets/releases) [![License](https://img.shields.io/github/license/claromes/waybacktweets)](https://github.com/claromes/waybacktweets/blob/main/LICENSE.md)
 
-        Tool that displays, via Wayback CDX Server API, multiple archived tweets on Wayback Machine to avoid opening each link manually. Users can define the number of tweets displayed per page and apply filters based on specific years. There is also an option to filter and view tweets that do not have the original URL available.
+        Tool that displays, via Wayback CDX Server API, multiple archived tweets on Wayback Machine to avoid opening each link manually. Users can apply filters based on specific years and view tweets that do not have the original URL available.
 
         This tool is a prototype, please feel free to send your [feedbacks](https://github.com/claromes/waybacktweets/issues). Created and maintained by [@claromes](https://github.com/claromes).
 
@@ -279,6 +279,9 @@ def display_not_tweet():
 
     response_html = requests.get(original_link)
 
+    if response_html.status_code not in range(200, 399):
+        st.warning('HTTP ERROR')
+
     if mimetype[i] == 'text/html' or mimetype[i] == 'warc/revisit' or mimetype[i] == 'unk':
         if ('.jpg' in tweet_links[i] or '.png' in tweet_links[i]) and response_html.status_code == 200:
             components.iframe(tweet_links[i], height=500, scrolling=True)
@@ -349,8 +352,6 @@ handle = st.text_input('Username', placeholder='jack')
 
 st.session_state.saved_at = st.slider('Tweets saved between', 2006, year, (2006, year))
 
-tweets_per_page = st.slider('Tweets per page', 25, 250, 25, 25)
-
 not_available = st.checkbox('Original URLs not available', help='Due to changes in X, it is possible to find available tweets if you are logged into X')
 
 query = st.button('Query', type='primary', use_container_width=True)
@@ -360,6 +361,7 @@ if handle != st.session_state.current_handle:
     st.session_state.offset = 0
 
 if query or st.session_state.count:
+    tweets_per_page = 25
 
     st.session_state.count = tweets_count(handle, st.session_state.saved_at)