From: Claromes Date: Tue, 25 Jun 2024 14:25:20 +0000 (-0300) Subject: update app params and update streamlit docs X-Git-Url: https://git.claromes.com/?a=commitdiff_plain;h=6aaf25427f2ede2c756244c1eb851b29b9e314c1;p=waybacktweets.git update app params and update streamlit docs --- diff --git a/app/app.py b/app/app.py index b274267..df41e67 100644 --- a/app/app.py +++ b/app/app.py @@ -2,6 +2,7 @@ import base64 from datetime import datetime, timedelta import streamlit as st +import streamlit.components.v1 as components from waybacktweets.api.export import TweetsExporter from waybacktweets.api.parse import TweetsParser @@ -56,11 +57,17 @@ if "count" not in st.session_state: if "archived_timestamp_filter" not in st.session_state: st.session_state.archived_timestamp_filter = (start_date, end_date) -if "username_param" not in st.session_state: - st.session_state.username_param = "" +if "username_value" not in st.session_state: + st.session_state.username_value = "" -if "expanded_param" not in st.session_state: - st.session_state.expanded_param = False +if "expanded_value" not in st.session_state: + st.session_state.expanded_value = False + +if "query" not in st.session_state: + st.session_state.query = False + +if "update_component" not in st.session_state: + st.session_state.update_component = 0 if "username" not in st.query_params: st.query_params["username"] = "" @@ -135,19 +142,34 @@ def tweets_exporter(parsed_tweets, username, field_options): return df, file_name -# ------Query Params ------ # +# ------ Custom JavaScript ------ # + + +def scroll_page(): + js = f""" + + """ # noqa: E501 + + components.html(js, width=0, height=0) + + +# ------ Query Param ------ # if st.query_params.username != "": - st.session_state.username_param = st.query_params.username - st.session_state.expanded_param = True + st.session_state.username_value = st.query_params.username + st.session_state.expanded_value = True + st.session_state.query = True -if st.query_params.username == "": - st.query_params.clear() + st.session_state.update_component += 1 + scroll_page() # ------ User Interface Settings ------ # st.info( - "🥳 [**Pre-release 1.0a5: Python module, CLI, and new Streamlit app**](https://github.com/claromes/waybacktweets/releases/tag/v1.0a5)" # noqa: E501 + "🥳 [**Pre-release 1.0x: Python module, CLI, and new Streamlit app**](https://github.com/claromes/waybacktweets/releases)" # noqa: E501 ) st.image(TITLE, use_column_width="never") @@ -172,12 +194,12 @@ st.divider() username = st.text_input( "Username *", - value=st.session_state.username_param, + value=st.session_state.username_value, key="username", placeholder="Without @", ) -with st.expander("Filtering", expanded=st.session_state.expanded_param): +with st.expander("Filtering", expanded=st.session_state.expanded_value): st.session_state.archived_timestamp_filter = st.date_input( "Tweets saved between", @@ -219,12 +241,16 @@ with st.expander("Filtering", expanded=st.session_state.expanded_param): query = st.button("Query", type="primary", use_container_width=True) +if st.query_params.username == "": + st.query_params.clear() + st.session_state.query = query + # ------ Results ------ # if username != st.session_state.current_username: st.session_state.current_username = username -if query or st.session_state.count: +if st.session_state.query or st.session_state.count: if unique: collapse = "urlkey" matchtype = "prefix" diff --git a/docs/streamlit.rst b/docs/streamlit.rst index ff96475..1c5f25a 100644 --- a/docs/streamlit.rst +++ b/docs/streamlit.rst @@ -18,6 +18,16 @@ Filters - Only unique Wayback Machine URLs: Filtering by the collapse option using the ``urlkey`` field and the URL Match Scope ``prefix`` +Username Query Parameter +-------------------------- + +An alternative way to access the application is by using the ``username`` query parameter. This allows for automatic configuration of the Username input and automatically searches. Additionally, when the ``username`` parameter is sent, the accordion with the filters will already be open. + +Example URL format: + +``https://waybacktweets.streamlit.app?username=`` + + Community Comments --------------------