How to get lots of tweets and filter by multiple strings in tweepy

Viewed 330

I have an Academic account on twitter and would like to get all the tweets in a month from a particular country that have one or more of a set of strings in them.

My attempt so far using v2 of the API is:

import tweepy

client = tweepy.Client(bearer_token=secret_token)


query = 'covid -is:retweet place_country:GB'

# Replace with time period of your choice
start_time = '2020-03-01T00:00:00Z'

# Replace with time period of your choice
end_time = '2020-04-01T00:00:00Z'

tweets = client.search_all_tweets(query=query, tweet_fields=['context_annotations', 'created_at', 'geo'],
                                  start_time=start_time, end_time=end_time,
                                  place_fields=['place_type', 'geo'], expansions='geo.place_id', max_results=500)

I believe (but could be wrong) that this returns 500 tweets that have GB as their geolocation , are not retweets, were created in March 2020 and contain the string "covid".

  • How can I replace "covid" with a set of strings that it should be searching for? For example ["covid", "coronavirus"].
  • How can I get it to return many more than 500 tweets? In theory I can extract more than million a month with the academic account but search_all_tweets has a limit of 500.
0 Answers
Related