I am using the tweepy
library in python
to search for tweets that contain a certain word. Retrieving all tweets results in a long list, which also includes a lot of retweets. I want to exclude these retweets. The following code works, but now each tweet is processed (also the retweets), which is not ideal considering the rate limit:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
query = 'test'
max_tweets = 100
for tweet in tweepy.Cursor(api.search, q=query).items(max_tweets):
jsontweet = json.dumps(tweet._json)
jsontweet = json.loads(jsontweet)
if not 'retweeted_status' in jsontweet:
print(tweet)
Is there a way in which I can specify within my search request to not include retweets? I found that I could include include_rts = False
in my code in this post, but I do not know where, and whether it is also working for the API.search
function. I was unable to find how to include this parameter in this function in the tweepy documentation.