Viktor Avdulov
Viktor Avdulov

Reputation: 157

How to set rate limit when using tweepy to collect retweeters form a set of tweet id's?

I have a long list of tweet id's (3200 to be exact). I am trying to collect all the retweets for all the tweets to build a network graph. Twitter limits the REST API calls for this one to 75 per 15 minute period. I am new to this, so does that mean 75 entities or I can get retweeters for 75 tweets? from Twitter Developer docs

In any case, how do I set up my code to not exceed the rate limit and yet go through the whole list of 3200 ids? This is what I have so far and it didn't work.

auth = tweepy.OAuthHandler('a', 'b')
auth.set_access_token('c', 'd')
api = tweepy.API(auth)

for attempt in range(75):
    for x in tweet_id_list:
        retweeters = []
        for status in api.retweets(x):
            retweeters.append(status.user.id)
    time.sleep(60 * 15)

Upvotes: 0

Views: 88

Answers (1)

thenerdsuperuser
thenerdsuperuser

Reputation: 31

Use the built-in notify functions:

auth = tweepy.OAuthHandler('a', 'b')
auth.set_access_token('c', 'd')
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

Upvotes: 1

Related Questions