當前位置: 首頁>>代碼示例>>Python>>正文


Python tweepy.StreamListener方法代碼示例

本文整理匯總了Python中tweepy.StreamListener方法的典型用法代碼示例。如果您正苦於以下問題:Python tweepy.StreamListener方法的具體用法?Python tweepy.StreamListener怎麽用?Python tweepy.StreamListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tweepy的用法示例。


在下文中一共展示了tweepy.StreamListener方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: initialize_listener

# 需要導入模塊: import tweepy [as 別名]
# 或者: from tweepy import StreamListener [as 別名]
def initialize_listener(self):
        if self.listener is None:

            class MyStreamListener(tweepy.StreamListener):
                def __init__(self, bot):
                    tweepy.StreamListener.__init__(self)
                    self.relevant_users = []
                    self.bot = bot

                def on_status(self, status):
                    if (
                        status.user.screen_name.lower() in self.relevant_users
                        and not status.text.startswith("RT ")
                        and status.in_reply_to_screen_name is None
                    ):
                        log.debug("On status from tweepy: %s", status.text)
                        tweet_message = stringify_tweet(status)
                        self.bot.say(f"B) New cool tweet from {status.user.screen_name}: {tweet_message}")

                def on_error(self, status_code):
                    log.warning("Unhandled in twitter stream: %s", status_code)
                    return super().on_error(status_code)

            self.listener = MyStreamListener(self.bot)
            self.reload() 
開發者ID:pajbot,項目名稱:pajbot,代碼行數:27,代碼來源:twitter.py

示例2: __init__

# 需要導入模塊: import tweepy [as 別名]
# 或者: from tweepy import StreamListener [as 別名]
def __init__(self, frontend_worker: 'TwitterWorker', credentials: TwitterApiCredentials,
                 retweet_replies_to_ids: List[int]):
        tweepy.StreamListener.__init__(self)
        self._worker = frontend_worker
        auth = tweepy.OAuthHandler(credentials.consumer_key, credentials.consumer_secret)
        auth.set_access_token(credentials.access_token, credentials.access_token_secret)
        self._api = tweepy.API(auth)
        self._retweet_replies_to_ids = retweet_replies_to_ids
        self._logger = logging.getLogger(self.__class__.__name__) 
開發者ID:csvance,項目名稱:armchair-expert,代碼行數:11,代碼來源:twitter.py

示例3: streamAPI

# 需要導入模塊: import tweepy [as 別名]
# 或者: from tweepy import StreamListener [as 別名]
def streamAPI(auth):
        # We instantiate our listener
        listener = StreamListener()
        # We start the streamer with the OAuth object and the listener
        streamer = tweepy.Stream(auth=auth, listener=listener)
        # We define the terms of which we want to track
        targetTerms = ['python']
        # We start the streamer, passing it our trackTerms
        streamer.filter(track=targetTerms) 
開發者ID:PacktPublishing,項目名稱:Learning-Python-Networking-Second-Edition,代碼行數:11,代碼來源:twitter_stream.py

示例4: __init__

# 需要導入模塊: import tweepy [as 別名]
# 或者: from tweepy import StreamListener [as 別名]
def __init__(self, twweeter_obj, time_limit=60):
        self.twweeter_obj = twweeter_obj
        super(StreamListener, self).__init__(self.twweeter_obj.api) 
開發者ID:CruiseDevice,項目名稱:twweet-cli,代碼行數:5,代碼來源:Listener.py


注:本文中的tweepy.StreamListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。