Python tweepy.streaming 模块,StreamListener() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用tweepy.streaming.StreamListener()

项目:ank    作者:sunary    | 项目源码 | 文件源码
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
项目:twitter_word_count    作者:prrateekk    | 项目源码 | 文件源码
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.