本文整理汇总了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)