Skip to content

Instantly share code, notes, and snippets.

@tacastillo
Created December 29, 2020 06:51
Show Gist options
  • Save tacastillo/cc1e9ec4c090b5a8515633fe35e0301f to your computer and use it in GitHub Desktop.
Save tacastillo/cc1e9ec4c090b5a8515633fe35e0301f to your computer and use it in GitHub Desktop.
Fetch Tweets for #66DaysOfData
from searchtweets import collect_results, gen_request_parameters, load_credentials
import requests
def fetch_tweets(until_id, results_per_call=10):
tweet_fields = ['author_id', 'lang', 'public_metrics', 'geo']
user_fields = ['name', 'username', 'location', 'public_metrics']
query = gen_request_parameters("#66DaysOfData -is:retweet",
results_per_call=results_per_call,
until_id=until_id,
tweet_fields=','.join(tweet_fields),
user_fields=','.join(user_fields)
)
results = collect_results(query,
max_tweets=results_per_call,
result_stream_args=search_args
)
tweets = results[:-1]
metadata = results[-1]
return tweets, metadata['oldest_id'], metadata['newest_id']
until_id = 0
newest_tweet_id = 0
for i in range(1):
tweets, oldest_id, newest_id = fetch_tweets(until_id)
print(tweets[0])
until_id = oldest_id
newest_tweet_id = newest_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment