twitterStream=Stream(OAuthObject,listenerFunction())
while True:
if twitterStream.running is True:
twitterStream.disconnect()
keywords=getKeywordsFromDb() # return string of keywords seaprated by comma
if keywords=='':
print 'no keywords to listen to'
else:
twitterStream.filter(track=[keywords],async=True) # Open the stream to work on asynchronously on a different thread
time.sleep(3600) # sleep for one hour
您可以从
on_status
或其他回调方法返回False
。这将取消流,该流将控制权返回给应用程序。在在
on_status
方法中,可以检查当前时间,如果已经过了三个小时,则返回False
。然后可以再次调用filter
,从数据库查询中传递不同的哈希标记。在当我查看流类构造函数并找到(async)参数并将其设置为true时,我解决了这个问题,下面是我的代码:
相关问题 更多 >
编程相关推荐