I'm using Tweepy
to write a function that will return all the followers for a large Twitter account and write them to a file. I've been reading about the Twitter rate limit but it still isn't quite making sense. The documentation says "15 calls every 15 minutes, and 180 calls every 15 minutes." However, when I run my code without the sleep function I manage to get around 280 names before twitter cuts me off. So how many calls am I actually making here? My code is as follows:
import tweepy
import time
auth = tweepy.OAuthHandler("...", "...")
auth.set_access_token("...", "...")
api = tweepy.API(auth)
f = open('output.txt', 'w')
timecount = 0
for user in tweepy.Cursor(api.followers, screen_name="NAME").items():
timecount = timecount + 1
if timecount == 200:
print "HOLD ON A SECOND!!!"
#print api.rate_limit_status()
time.sleep(60*15)
timecount = 0
data = user.screen_name
print user.screen_name
print >> f, data
f.close()
Right now it's waiting 15 minutes between every 280 names it gets which seems to be working. Obviously, I want this to run as efficiently as possible. Can anyone help me understand how many calls I'm making how long I should be waiting?