本文整理匯總了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()
示例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__)
示例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)
示例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)