add ascending and descending by timestamp
authorClaromes <claromes@hey.com>
Tue, 4 Jun 2024 20:26:50 +0000 (17:26 -0300)
committerClaromes <claromes@hey.com>
Tue, 4 Jun 2024 20:26:50 +0000 (17:26 -0300)
waybacktweets/export_tweets.py
waybacktweets/main.py
waybacktweets/request_tweets.py

index 2e0708b5dabf392f2ceb6d654459fabdad497cc1..fcd648ce6655022b93ff13037e777a3df3e35631 100644 (file)
@@ -8,10 +8,11 @@ from viz_tweets import HTMLTweetsVisualizer
 class TweetsExporter:
     """Handles the exporting of parsed archived tweets."""
 
-    def __init__(self, data, username, metadata_options):
+    def __init__(self, data, username, metadata_options, ascending):
         self.data = data
         self.username = username
         self.metadata_options = metadata_options
+        self.ascending = ascending
         self.formatted_datetime = self.datetime_now()
         self.filename = f'{self.username}_tweets_{self.formatted_datetime}'
         self.dataframe = self.create_dataframe(self)
@@ -46,6 +47,8 @@ class TweetsExporter:
 
         df = pd.DataFrame(data_transposed, columns=self.metadata_options)
 
+        df = df.sort_values(by="archived_timestamp", ascending=self.ascending)
+
         return df
 
     def save_to_csv(self):
index 1463cfc6faf78e87901120fa47763d3dc04bed54..66bdfb304639eb031a88aad00e504d3fc12efc4b 100644 (file)
@@ -10,6 +10,7 @@ username = 'claromes'
 unique = False
 datetime_from = ''
 datetime_to = ''
+ascending = False
 
 
 def main():
@@ -32,7 +33,7 @@ def main():
             parsed_tweets = parser.parse()
 
             exporter = TweetsExporter(parsed_tweets, username,
-                                      metadata_options)
+                                      metadata_options, ascending)
             exporter.save_to_csv()
             # exporter.save_to_json()
             # exporter.save_to_html()
index 2410366837f4a6bf8d6211ad90972ee451eb4c87..540f693a8b2ac051f36cad056818b4e27e3069b3 100644 (file)
@@ -21,7 +21,7 @@ class WaybackTweets:
 
         url = (
             f'https://web.archive.org/cdx/search/cdx?url=https://twitter.com/{self.username}/status/*'
-            f'&output=json{unique_param}{timestamp_from_param}{timestamp_to_param}&limit=5'
+            f'&output=json{unique_param}{timestamp_from_param}{timestamp_to_param}&limit=20'
         )
         print(f'Getting and parsing archived tweets from {url}')