我找到了下面的代码,可以很好地在Python Shell中让我查看推特火箭筒的标准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'])
我该如何添加过滤器以仅解析来自特定位置的推文?我看到其他与Twitter相关的Python代码中添加了GPS,但我在Tweepy模块中找不到任何特定于sapi的内容。
有什么想法吗?
谢谢