本文整理匯總了Python中tweepy.streaming.StreamListener方法的典型用法代碼示例。如果您正苦於以下問題:Python streaming.StreamListener方法的具體用法?Python streaming.StreamListener怎麽用?Python streaming.StreamListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tweepy.streaming
的用法示例。
在下文中一共展示了streaming.StreamListener方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init_app
# 需要導入模塊: from tweepy import streaming [as 別名]
# 或者: from tweepy.streaming import StreamListener [as 別名]
def init_app(self, key):
self.key = key
self.listener = StreamListener()
self.listener.on_data = self.on_messages_received
self.listener.on_error = self.on_error
示例2: on_data
# 需要導入模塊: from tweepy import streaming [as 別名]
# 或者: from tweepy.streaming import StreamListener [as 別名]
def on_data(self, data):
global count
# Loop keeps on fetching data and incrementing count until the time limit is reached.
while ((time.time() - self.time) < self.limit):
try:
count+=1
return True
except BaseException as e:
time.sleep(5)
pass
return False
# StreamListener Class Ends Here.
# REST API that fetches data from the past days till today.
# As per the API documentation twitter allows the user to access Tweets that are no more than 7 days old.