Skip to content

Commit

Permalink
app - update archived_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
claromes committed Jul 24, 2024
1 parent 0e7a3a1 commit 6c76043
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

collapse = None
matchtype = None
start_date = datetime.now() - timedelta(days=30 * 6)
start_date = datetime.now() - timedelta(days=365)
end_date = datetime.now()
min_date = datetime(2006, 1, 1)

Expand Down Expand Up @@ -55,7 +55,7 @@
st.session_state.count = False

if "archived_timestamp_filter" not in st.session_state:
st.session_state.archived_timestamp_filter = (start_date, end_date)
st.session_state.archived_timestamp_filter = None

if "username_value" not in st.session_state:
st.session_state.username_value = ""
Expand Down Expand Up @@ -124,15 +124,13 @@ def wayback_tweets(
return archived_tweets


@st.cache_data(ttl=600, show_spinner=False)
def tweets_parser(archived_tweets, username, field_options):
parser = TweetsParser(archived_tweets, username, field_options)
parsed_tweets = parser.parse()

return parsed_tweets


@st.cache_data(ttl=600, show_spinner=False)
def tweets_exporter(parsed_tweets, username, field_options):
exporter = TweetsExporter(parsed_tweets, username, field_options)

Expand Down Expand Up @@ -197,34 +195,33 @@ def scroll_page():

with st.expander("Filtering", expanded=st.session_state.expanded_value):

st.session_state.archived_timestamp_filter = st.date_input(
"Tweets saved between",
(start_date, end_date),
min_date,
end_date,
format="YYYY/MM/DD",
help="Using the `from` and `to` filters. Format: YYYY/MM/DD",
)
st.caption(
":orange[note: large date range takes a long time to process, and the app's resources may not be sufficient. Try to perform searches with smaller ranges to get faster results.]" # noqa: E501
)

col1, col2 = st.columns(2)

with col1:
limit = st.text_input(
limit = st.number_input(
"Limit",
value=500,
max_value=500,
key="limit",
help="Query result limits",
help="Query result limits. A maximum of 500 tweets per search to enhance the tool's performance", # noqa: E501
)

with col2:
offset = st.text_input(
"Offset",
key="offset",
help="Allows for a simple way to scroll through the results",
help="Enables efficient pagination. For instance, after retrieving an initial batch of 500 tweets, setting an offset of 500 fetches the next batch from 501 to 1000", # noqa: E501
)

st.session_state.archived_timestamp_filter = st.date_input(
"Tweets saved between",
None,
min_date,
end_date,
format="YYYY/MM/DD",
help="Using the `from` and `to` filters. Format: YYYY/MM/DD",
)

unique = st.checkbox(
"Only unique Wayback Machine URLs",
key="unique",
Expand All @@ -251,15 +248,22 @@ def scroll_page():
collapse = "urlkey"
matchtype = "prefix"

archived_timestamp_from = None
archived_timestamp_to = None

if st.session_state.archived_timestamp_filter:
archived_timestamp_from = st.session_state.archived_timestamp_filter[0]
archived_timestamp_to = st.session_state.archived_timestamp_filter[1]

try:
with st.spinner(
f"Waybacking @{st.session_state.current_username}'s archived tweets"
):
wayback_tweets = wayback_tweets(
st.session_state.current_username,
collapse,
st.session_state.archived_timestamp_filter[0],
st.session_state.archived_timestamp_filter[1],
archived_timestamp_from,
archived_timestamp_to,
limit,
offset,
matchtype,
Expand Down

0 comments on commit 6c76043

Please sign in to comment.