我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用tweepy.StreamListener()。
def tweet_listener(): consumer_key = os.getenv("consumer_key") consumer_secret = os.getenv("consumer_secret") access_token = os.getenv("access_token") access_token_secret = os.getenv("access_token_secret") auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) while True: try: stream = tweepy.Stream(auth=api.auth, listener=StreamListener(api)) print("listener starting...") stream.userstream() except Exception as e: print(e) print(e.__doc__)
def tweet_listener(): auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) api = tweepy.API(auth) while True: try: stream = tweepy.Stream(auth=api.auth, listener=StreamListener(api)) print("listener starting...") stream.userstream() except Exception as e: print(e) print(e.__doc__)
def __init__(self, api): self.api = api super(tweepy.StreamListener, self).__init__() client = KafkaClient("localhost:9092") self.producer = SimpleProducer(client, async = True, batch_send_every_n = 1000, batch_send_every_t = 10)
def __init__(self, fd, time_limit): """ :param fd: :param time_limit: in seconds :return: """ self.fd = fd self.time_limit = time_limit self.start_time = time.time() super(StreamListener, self).__init__()
def __init__(self, handler): self.handler = handler tweepy.StreamListener.__init__(self)
def __init__(self, socketio): manager = CredentialsManager(settings.CREDENTIALS_PATH) cred = manager.read() auth = tweepy.OAuthHandler(cred['twitter_api_key'] , cred['twitter_api_secret']) auth.set_access_token(cred['access_token'], cred['access_token_secret']) self.stream = tweepy.Stream(auth, StreamListener(socketio))
def __init__(self, api=None): super(StreamListener, self).__init__() self.counter = 0 self.limit = 500 self.tweet_list = []
def search(): stream_listener = StreamListener() stream = tweepy.Stream(auth=api.auth, listener=stream_listener) stream.filter(track=TOPICS) return
def __init__(self, api, producer, topic_name, symbols): """ Listener initilizer :param api: tweepy api :param producer: Kafka producer :param topic_name: tweet topic the kafka producer sent by :param symbols: stock list :return: None """ self.api = api self.producer = producer self.topic_name = topic_name self.symbols = symbols super(tweepy.StreamListener, self).__init__() print("Initiating Listener, topic is %s" % self.topic_name)
def __init__(self, api): super(tweepy.StreamListener, self).__init__() print("Will create Twitter stream listener") self.on_connect_cb = None self.on_timeout_cb = None self.on_error_cb = None self.on_status_cb = None self.api = api print("Did create Twitter stream listener")