[英]Python tweepy find all tweets in the Netherlands
UPDATE BOTTOM OF THE QUESTION: 更新问题的底部:
I am attempting to create a script that generates all geocoded tweets in the Netherlands. 我正在尝试创建一个脚本,在荷兰生成所有地理编码的推文。 I am a long way from getting there.
到达那里我还有很长的路要走。 While I was playing around with Tweepy I ran into a weird situation.
当我和Tweepy玩耍的时候,我遇到了一个奇怪的情况。 I found a script online which could search for tweets containing a keyword.
我在网上找到了一个可以搜索包含关键字的推文的脚本。 I tried to add a parameter checking for a geocode.
我试图添加一个参数检查地理编码。 I succeeded and the underneath script works.
我成功了,底层脚本有效。 However, when I delete the geocode part of the tweepy.Cursos() call it does not work anymore.
但是,当我删除tweepy.Cursos()调用的地理编码部分时,它不再起作用。 So this script works:
所以这个脚本有效:
import tweepy
import csv
consumer_key = "???"
consumer_secret = "???"
access_token = "???"
access_token_secret = "???"
auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('tweets.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,q="*",count=100,geocode="5.29126,52.132633,150km").items(100):
print [tweet.created_at, tweet.text.encode('utf-8'), tweet.user.id, tweet.geo]
csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8'), tweet.user.id])
UPDATE! UPDATE! Thank you for helping me so far.
谢谢你帮助我到目前为止。 Now I have another question regarding my goal to create a script to gather all georeferenced tweets in the Netherlands.
现在我有另一个问题,我的目标是创建一个脚本来收集荷兰的所有地理参考推文。
The last part of my code should return all geocoded tweets in the Netherlands and write it into a CSV file. 我的代码的最后一部分应返回荷兰的所有地理编码推文并将其写入CSV文件。 Unfortunately it only seems to take Tweets in the English language.
不幸的是,它似乎只是用英语推文。 Since there is no Dutch language setting, and Dutch people also Tweet in English, I do not want to set the language of the search.
由于没有荷兰语设置,荷兰人也用英语推文,我不想设置搜索语言。 Why is it only searching Tweets in the English language?
为什么只用英语搜索推文? I do not know where I am setting this characteristic of the search.
我不知道我在哪里设置搜索的这个特征。
Oh i turned around lat lon. 哦,我转过拉特隆。 Stupid mistake.
愚蠢的错误。 Question is answered!
问题得到解答!
You can only set your query string to '*'
when also using the geocode
parameter. 在使用
geocode
参数时,您只能将查询字符串设置为'*'
。 A search for q='*'
without a specified geocode
is invalid. 在没有指定
geocode
q='*'
情况下搜索q='*'
无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.