From 23b907555ef2b16a9e97f2c9a31c1ded5030afa1 Mon Sep 17 00:00:00 2001 From: Claromes Date: Sat, 13 May 2023 01:54:20 -0300 Subject: [PATCH] pagination --- app.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index bb7603b..29e7b96 100644 --- a/app.py +++ b/app.py @@ -93,7 +93,7 @@ st.title('Wayback Tweets [![Fork me on GitHub](https://img.shields.io/badge/-For 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, key='init') +query = st.button('Query', type='primary', use_container_width=True) if query or handle: with st.spinner(''): @@ -111,8 +111,23 @@ if query or handle: return_none_count = 0 - for i, link in enumerate(parsed_links): - tweet = embed('{}'.format(tweet_links[i])) + if 'current_index' not in st.session_state: + st.session_state.current_index = 0 + + previous, _ , next = st.columns([3, 4, 3]) + + if previous.button('Previous', type='primary', use_container_width=True): + st.session_state.current_index -= 50 + + if next.button('Next', type='primary', use_container_width=True): + st.session_state.current_index += 50 + + start_index = st.session_state.current_index + end_index = min(len(parsed_links), start_index + 50) + + for i in range(start_index, end_index): + link = parsed_links[i] + tweet = embed(tweet_links[i]) if not only_deleted: attr(i) @@ -138,5 +153,8 @@ if query or handle: progress.write('{}/{} URLs have been captured'.format(return_none_count, len(parsed_links))) + if st.session_state.current_index >= len(parsed_links): + st.session_state.current_index = 0 + if not links: st.error('Unable to query the Wayback Machine API.') -- 2.34.1