Okym
Okym

Reputation: 259

How do I ignore tweets that I have already retweeted in Tweepy?

I am trying to ignore tweets that I myself have already retweeted but I don't really know how to specify that, I know that 'if not tweet.retweeted:' ignores retweets but I am not sure how to ignore tweets that I already retweeted in my Twitter api search.

for tweet in tweepy.Cursor(api.search,
                   q='- Play Free Spin http://csgoroll.com/freespin',
                   since='2017-12-20',
                   screen_name='CSGORoll'
                   ).items(10):
            if not tweet.retweeted:
                    tweet.retweet()
                    print("CSGORoll, Working...")
                    return

Upvotes: 3

Views: 1502

Answers (1)

Krishna Shamanth
Krishna Shamanth

Reputation: 46

If your issue is that the script is not continuing, you can use try and except instead.

try:
    tweet.retweet()
except tweepy.TweepError as e:
    print(e)

In this case, you'll get the following message printed and will continue to retweet next tweets that are matching your search.

Output: [{u'message': u'You have already retweeted this Tweet.', u'code': 327}]

Upvotes: 3

Related Questions