From: Claromes Date: Wed, 12 Jun 2024 09:04:09 +0000 (-0300) Subject: Add --offset X-Git-Url: https://git.claromes.com/?a=commitdiff_plain;h=654ff7a3be749a77ac61b2d77f96ba81dcedca04;p=waybacktweets.git Add --offset --- diff --git a/app/app.py b/app/app.py index 329034e..19a3ce5 100644 --- a/app/app.py +++ b/app/app.py @@ -210,6 +210,7 @@ if query or st.session_state.count: st.session_state.archived_timestamp_filter[0], st.session_state.archived_timestamp_filter[1], tweets_per_page, + st.session_state.offset, ) archived_tweets = response.get() diff --git a/waybacktweets/cli.py b/waybacktweets/cli.py index 23596ec..d308e93 100644 --- a/waybacktweets/cli.py +++ b/waybacktweets/cli.py @@ -46,7 +46,13 @@ def parse_date(ctx, param, value): help="Filtering by date range up to this date.", ) @click.option("--limit", type=int, default=None, help="Query result limits.") -def cli(username, unique, timestamp_from, timestamp_to, limit): +@click.option( + "--offset", + type=int, + default=None, + help="Allows for a simple way to scroll through the results.", +) +def cli(username, unique, timestamp_from, timestamp_to, limit, offset): """ Retrieves archived tweets' CDX data from the Wayback Machine, performs necessary parsing, and saves the data. @@ -54,7 +60,9 @@ def cli(username, unique, timestamp_from, timestamp_to, limit): USERNAME: The Twitter username without @. """ try: - api = WaybackTweets(username, unique, timestamp_from, timestamp_to, limit) + api = WaybackTweets( + username, unique, timestamp_from, timestamp_to, limit, offset + ) archived_tweets = api.get() if archived_tweets: diff --git a/waybacktweets/request_tweets.py b/waybacktweets/request_tweets.py index b6c561e..f6a138b 100644 --- a/waybacktweets/request_tweets.py +++ b/waybacktweets/request_tweets.py @@ -7,12 +7,13 @@ from waybacktweets.utils import get_response class WaybackTweets: """Requests data from the Wayback CDX Server API and returns it in JSON format.""" - def __init__(self, username, unique, timestamp_from, timestamp_to, limit): + def __init__(self, username, unique, timestamp_from, timestamp_to, limit, offset): self.username = username self.unique = unique self.timestamp_from = timestamp_from self.timestamp_to = timestamp_to self.limit = limit + self.offset = offset def get(self): """GET request to the Internet Archive's CDX API to retrieve archived tweets.""" @@ -34,6 +35,9 @@ class WaybackTweets: if self.limit: params["limit"] = self.limit + if self.offset: + params["offset"] = self.offset + print("Making a request to the Internet Archive...") try: