From a69e4f5d03afef1e33af9017685f1319dc5265bf Mon Sep 17 00:00:00 2001 From: Sam Hames Date: Tue, 17 Aug 2021 16:39:01 +1000 Subject: [PATCH] Move last-30-days by default fix from the CLI to the client This fixes bugs in timelines and conversations, which use the search_all endpoint without the fix, therefore limiting them to the last 30 days only. This fix just moves the default start_time set in the CLI app to the client app, so it will apply by default to all uses of the search_all method. --- twarc/client2.py | 9 ++++++++- twarc/command2.py | 6 ------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/twarc/client2.py b/twarc/client2.py index 360b9f66..85c47e02 100644 --- a/twarc/client2.py +++ b/twarc/client2.py @@ -212,7 +212,8 @@ def search_all( until_id (int): Return all tweets up to this tweet_id. start_time (datetime): - Return all tweets after this time (UTC datetime). + Return all tweets after this time (UTC datetime). If none of start_time, since_id, or until_id + are specified, this defaults to 2006-3-21 to search the entire history of Twitter. end_time (datetime): Return all tweets before this time (UTC datetime). max_results (int): @@ -223,6 +224,12 @@ def search_all( """ url = "https://api.twitter.com/2/tweets/search/all" + # start time defaults to the beginning of Twitter to override the + # default of the last month. Only do this if start_time is not already + # specified and since_id and until_id aren't being used + if start_time is None and since_id is None and until_id is None: + start_time = datetime.datetime(2006, 3, 21, tzinfo=datetime.timezone.utc) + return self._search( url, query, diff --git a/twarc/command2.py b/twarc/command2.py index fd81ae03..620c0e58 100644 --- a/twarc/command2.py +++ b/twarc/command2.py @@ -234,12 +234,6 @@ def _search( # default number of tweets per response 500 when not set otherwise if max_results == 0: max_results = 100 # temp fix for #504 - - # start time defaults to the beginning of Twitter to override the - # default of the last month. Only do this if start_time is not already - # specified and since_id and until_id aren't being used - if start_time is None and since_id is None and until_id is None: - start_time = datetime.datetime(2006, 3, 21, tzinfo=datetime.timezone.utc) else: if max_results == 0: max_results = 100