Python tweepy.StreamListener() Examples

The following are 5 code examples of tweepy.StreamListener(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tweepy , or try the search function .
Example #1
Source File: twitter.py    From pajbot with MIT License 7 votes vote down vote up
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() 
Example #2
Source File: twitter_stream.py    From Learning-Python-Networking-Second-Edition with MIT License 7 votes vote down vote up
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) 
Example #3
Source File: twitter.py    From armchair-expert with MIT License 5 votes vote down vote up
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__) 
Example #4
Source File: Listener.py    From twweet-cli with MIT License 5 votes vote down vote up
def __init__(self, twweeter_obj, time_limit=60):
        self.twweeter_obj = twweeter_obj
        super(StreamListener, self).__init__(self.twweeter_obj.api) 
Example #5
Source File: Listener.py    From twweet-cli with MIT License 5 votes vote down vote up
def __init__(self, twweeter_obj):
        self.twweeter_obj = twweeter_obj
        self.stream_listener_ob = StreamListener(self.twweeter_obj)

    # authorise the StreamListener