TwitterApiScrap.py 文件源码

python
阅读 54 收藏 0 点赞 0 评论 0

项目:crawler-twitter 作者: sidgleyandrade 项目源码 文件源码
def init(self):
        auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret)
        auth.set_access_token(self.access_token, self.access_token_secret)

        try:
            my_stream_listener = MyStreamListener
            my_stream = tweepy.Stream(auth=auth,
                                      listener=my_stream_listener(
                                          crud=self.CRUD,
                                          conn_sec=self.conn_sec,
                                          conn_schema=self.conn_schema,
                                          conn_table=self.conn_table))

            # Choose the kind of stream - either bounding box or word track.
            if self.search_word:
                my_stream.filter(track=[self.search_word], async=True)
            else:
                my_stream.filter(locations=self.geo, async=True)

            # Check if the connection stream is active and
            # break if it is not. init() function will restart
            # the connection stream.
            self.running = my_stream.running
            while True:
                if not my_stream.running:
                    self.running = False
                    time.sleep(60)  # Check each 60 sec.
                    break
        except Exception as e:
            logging.error(e)
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号