Tom
Tom

Reputation: 43

Filter out own retweets Tweepy

My application (Python3 + Tweepy) finds a hashtag and retweets it. I get a "Retweet is not permissible for this status" error because of retweeting own tweets.

How to filter out?

# retweet function
def hashtag_Retweet():    
    print (tweet.id)   
    api.retweet(tweet.id) # retweet
    print(tweet.text)
    return

query = '#foosball'
our_own_id = '3678887154' #Made up for this post
tweets = api.search(query)
for tweet in tweets:
# make sure that tweet does not come from host    
    hashtag_Retweet()

Upvotes: 0

Views: 308

Answers (1)

lrnzcig
lrnzcig

Reputation: 3947

Something like this would work.

for tweet in tweets:
    if tweet.user.id != our_own_id:     
        hashtag_Retweet()

Hope it helps.

Upvotes: 1

Related Questions