python - Python 代码不等待 Tweepy wait_on_rate_limit
问题描述
我正在使用 Tweepy Twitter API 和 Python 使用以下代码检索相当多的推文(约 40,000 条):
def getTweets(query, num):
#gets the specified number of tweets
_max_queries = 100
tweets = tweet_batch = api.search(q=query, count=num, tweet_mode='extended')
ct = 1
while len(tweets) < num and ct < _max_queries:
print("Got %d tweets!" % (len(tweets)))
tweet_batch = api.search(q=query, count=num-len(tweets), max_id=tweet_batch.max_id, tweet_mode='extended')
tweets.extend(tweet_batch)
ct += 1
return tweets
我将 api wait_on_rate_limit 设置为 true。在我调用 getTweets() 函数后,我立即尝试处理推文。唯一的问题是 Python 没有等待 Tweepy 的速率限制重置,而是过早地继续执行进程代码。例如,如果我尝试提取 20,000 条推文,Tweepy 会提取大约 9,000 条并立即处理它们,而不是等待速率限制重置,然后再提取其余的推文。有什么建议么?
解决方案
推荐阅读
- php - 从php编号中删除引号
- json - How to sort data using Jora in JSON Discovery Report
- jquery - Is it possible to start -webkit-animation at a paused state before clicking the run button?
- json - 我怎样才能得到这个对象的价值?
- node.js - 降级节点出现错误“无效版本”
- android - 如何允许用户从 Firebase 中删除他们的帖子?
- c# - 如何在 docker 容器中运行 asp.net 核心应用程序?
- gradle - gradle构建成功后,运行spring boot应用程序时找不到类
- mysql - 使用 Pandas 通过 SSH 隧道在 AWS 上查询我的数据库
- android - 为什么我的 Gradle 在我的 Unity Android 版本上失败?