From: Claromes Date: Tue, 4 Jun 2024 20:26:50 +0000 (-0300) Subject: add ascending and descending by timestamp X-Git-Url: https://git.claromes.com/?a=commitdiff_plain;h=95360b34bd9ee2e0629295e912b484c513cdf977;p=waybacktweets.git add ascending and descending by timestamp --- diff --git a/waybacktweets/export_tweets.py b/waybacktweets/export_tweets.py index 2e0708b..fcd648c 100644 --- a/waybacktweets/export_tweets.py +++ b/waybacktweets/export_tweets.py @@ -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): diff --git a/waybacktweets/main.py b/waybacktweets/main.py index 1463cfc..66bdfb3 100644 --- a/waybacktweets/main.py +++ b/waybacktweets/main.py @@ -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() diff --git a/waybacktweets/request_tweets.py b/waybacktweets/request_tweets.py index 2410366..540f693 100644 --- a/waybacktweets/request_tweets.py +++ b/waybacktweets/request_tweets.py @@ -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}')