python - 使用 bounding_box 收集 Twitter 流
问题描述
我正在使用 tweepy.Cursor 来收集推文,它工作正常,我想改进我的代码,以通过 bounding_box 将推文的收集限制为给定的坐标对。我对python的了解非常有限。我需要帮助来改进此代码。代码如下:
import sys
import os
import jsonpickle
import tweepy
import datetime
import time
consumer_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
maxTweets = 1000000
tweetCount = 0
stamp = time.strftime('%b%d%y%H%M')
filename = 'AFG'+stamp+'.json'
print(filename)
searchQuery = ('afghanistan OR elections')
with open(filename, 'w') as f:
for tweet in tweepy.Cursor(api.search, q=searchQuery, tweet_mode='extended').items(maxTweets):
f.write(jsonpickle.encode(tweet._json, unpicklable=False) + '\n')
tweetCount += 1
print("Downloaded {0} tweets.". format(tweetCount))
我不知道在上面的代码中将 bounding_box 放在哪里。阿富汗的 Bounding_box 是:'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432))
解决方案
推荐阅读
- elasticsearch - 弹性搜索查询,只返回最重要的唯一结果
- r - 计算 R 数据框列中变量值的唯一组合
- vbscript - 如何在 Visual Basic(经典 ASP)中用直引号替换智能引号?
- django - How to remove csrf token from search result url in Django?
- android-studio - Not have drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi
- angular - 通过 URL 从 Angular 应用程序提供文件
- spring - spring webflux - 不要为特定路径创建会话
- c# - Group By then Select内部元素Linq asp.net Core 3
- python - 我可以将 Conda 与从源代码构建的 python 版本一起使用吗?
- sql - DUPLICATE KEY UPDATE 上的字符串比较在 SQL 中不起作用