Skip to content

Commit

Permalink
update app params and update streamlit docs
Browse files Browse the repository at this point in the history
  • Loading branch information
claromes committed Jun 25, 2024
1 parent bd63c88 commit 6aaf254
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
52 changes: 39 additions & 13 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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
Expand Down Expand Up @@ -56,11 +57,17 @@
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"] = ""
Expand Down Expand Up @@ -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"""
<script>
window.parent.document.querySelector('section.main').scrollTo(700, 700);
let update_component = {st.session_state.update_component} // Force component update to generate scroll
</script>
""" # 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")
Expand All @@ -172,12 +194,12 @@ def tweets_exporter(parsed_tweets, username, field_options):

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",
Expand Down Expand Up @@ -219,12 +241,16 @@ def tweets_exporter(parsed_tweets, username, field_options):

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"
Expand Down
10 changes: 10 additions & 0 deletions docs/streamlit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<USERNAME>``


Community Comments
--------------------

Expand Down

0 comments on commit 6aaf254

Please sign in to comment.