我有以下代码,它允许我通过python查看1%的twitter firehose流:
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):
if '' in status.text.lower():
print status.text
print status.coordinates
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=['example'])
我知道语法include_rts = False
将从我正在查看的流中删除转推,但我不确定将其添加到上述代码的位置。
有人可以帮忙吗?
由于
答案 0 :(得分:0)
将以下条件添加到侦听器中的on_status函数:
def on_status(self, status):
if '' in status.text.lower() and 'retweeted_status' not in status:
print status.text
print status.coordinates