I am using Tweepy with python and trying to get the original tweets authored by set of users (i.e., I want to exclude any tweet in their timeline that is actually a retweet). How can I do this with Tweepy? I tried something like this and I do not know if it works:
tweets = api.user_timeline(id=user['id'], count=30)
for tweet in tweets:
if not tweet.retweeted:
analyze_tweet(tweet)
Does the api.user_timeline()
return only original tweets? Or retweets of this user as well?
Tweepy by default doesn't include retweets in user_timeline therefore tweet.retweeted will always be false. To include retweets you can specify include_rts as True like
tweets= api.user_timeline(id=user['id'], count=30,include_rts=True)
for tweet in tweets:
if not tweet.retweeted:
analyze_tweet(tweet)
else:
#do something with retweet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With