I'm trying to get the below done, but keep getting an error. I know that I'm getting the information from Twitter because my monthly usage increasing. Any help would be appreciated.
Search Twitter for 5000 tweets mentioning the hashtag #covid and store them in a file titled tweets.txt
. You should clean the tweets and make sure that one tweet is stored per line in the file, i.e. the tweets.txt
file should exactly have 5000 lines (this can be done by replacing \n
in the tweet text with a “ ”).
This is what I have so far:
import tweepy
API_KEY = “My key will be here.”
client = tweepy.Client(API_KEY)
query = "covid"
response = client.search_recent_tweets(query)
for tweet in tweepy.Paginator(client.search_recent_tweets, query=query, max_results=10).flatten(limit=5000):
save_file = open('tweets.txt', 'w')
for tweet in tweepy:
tweet = tweet.strip()
save_file.write(tweet + ' ')
print(tweet)
save_file.close()