Add --offset
authorClaromes <claromes@hey.com>
Wed, 12 Jun 2024 09:04:09 +0000 (06:04 -0300)
committerClaromes <claromes@hey.com>
Wed, 12 Jun 2024 09:04:09 +0000 (06:04 -0300)
app/app.py
waybacktweets/cli.py
waybacktweets/request_tweets.py

index 329034ebfc0d26ddcdc2444cb8b9d5b8be7af96b..19a3ce56a4aa11c8effc676813104adfae68ee4e 100644 (file)
@@ -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()
 
index 23596ecc6d436422ee238108187d78365260f37e..d308e9330382f7eedafdf2ea4d3dda9fc21148bb 100644 (file)
@@ -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:
index b6c561e47313f884693a1120a93031ab31b7c27c..f6a138b67354c980aa23de508753dff1d214b669 100644 (file)
@@ -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: