【发布时间】:2015-08-05 04:01:17
【问题描述】:
我正在使用Tweepy 编写一个函数,该函数将返回一个大型 Twitter 帐户的所有关注者并将它们写入一个文件。我一直在阅读有关 Twitter 速率限制的信息,但它仍然不太有意义。文档说“每 15 分钟打 15 个电话,每 15 分钟打 180 个电话”。然而,当我在没有睡眠功能的情况下运行我的代码时,我设法在 twitter 打断我之前获得了大约 280 个名字。那么我实际上在这里打了多少电话?我的代码如下:
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()
现在它在每 280 个名称之间等待 15 分钟,这似乎是有效的。显然,我希望它尽可能高效地运行。谁能帮我了解我打了多少电话我应该等多久?
【问题讨论】: