我发现下面这段代码非常适合让我在Python Shell中查看twitter firehose的标准1%:
import sys
import tweepy
consumer_key=""
consumer_secret=""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print status.text
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['manchester united'])
Run Code Online (Sandbox Code Playgroud)
如何添加过滤器以仅解析特定位置的推文?我见过人们将GPS添加到其他与Twitter相关的Python代码中,但我无法在Tweepy模块中找到任何特定于sapi的内容.
有任何想法吗?
谢谢
存储在'created_at'字段中的日期是否通过PyMongo封送到Python日期时间对象,还是我必须用Python Date对象手动替换文本字符串?即
我不得不用Python日期对象替换日期字符串似乎非常不自然,这就是为什么我在问这个问题.
我想编写显示过去三天推文的查询.如果有一个光滑的方式,请告诉我.谢谢!