Python Forum

Full Version: Check if tweet is favorited by myself | TWEEPY
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On Tweepy, I get too many "You have already favorite this tweet" error and when it gives this error repeatedly, the API rate limit error[code 429] is issued.

Before attempting to favorite the tweet to resolve this issue, before favorite the tweet I want to check if the tweet is not favourited by me. But I haven't been able to enter the while / else command in my code, I would appreciate if anyone could help.

I tried the code below and added the part "favorited = status.favorited" where am I doing wrong?

import tweepy
import time

auth = tweepy.OAuthHandler('secret_credentials','secret_credentials')
auth.set_access_token('access_token','access_token')

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
user = api.me()


for tweet in tweepy.Cursor(api.search, q="books", result_type="recent").items(70):

   status = api.get_status(tweet) 
   favorited = status.favorited
      
   if favorited == False: 

    try:
        print('Tweet Liked')
        tweet.favorite()
        time.sleep(10)
    except tweepy.TweepError as e:
        print(e.reason)
    except StopIteration: 
        break