当前位置: 首页>>代码示例>>Python>>正文


Python tweepy.Stream方法代码示例

本文整理汇总了Python中tweepy.Stream方法的典型用法代码示例。如果您正苦于以下问题:Python tweepy.Stream方法的具体用法?Python tweepy.Stream怎么用?Python tweepy.Stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tweepy的用法示例。


在下文中一共展示了tweepy.Stream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def initialize():

	output = TwitterStreamListener()

	# setup Twitter API connection details
	twitter_auth = OAuthHandler( TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET )
	twitter_auth.set_access_token( TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET )
	
	# connect to Twitter Streaming API
	twitter_stream = Stream( twitter_auth, output )

	# filter tweets using track, follow and/or location parameters
	# https://dev.twitter.com/streaming/reference/post/statuses/filter
	twitter_stream.filter(track=[ TWITTER_HASHTAG ])


# def cleanup():
# 	twitter_stream.disconnect() 
开发者ID:jpescada,项目名称:TwitterPiBot,代码行数:20,代码来源:twitter_client.py

示例2: __init__

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def __init__(self, auth, listener, retry_count, logger, min_http_delay=5,
		max_http_delay=320, min_http_420_delay=60, min_tcp_ip_delay=0.5,
		max_tcp_ip_delay=16, **options):

		self.logger = logger
		self.logger.info('COMPLIENT STREAM: Initializing complient stream...')
		self.min_http_delay = min_http_delay
		self.max_http_delay = max_http_delay
		self.min_tcp_ip_delay = min_tcp_ip_delay
		self.max_tcp_ip_delay = max_tcp_ip_delay
		self.running = False
		self.retry_count = retry_count
		self.auth = auth

		#Twitter sends a keep-alive every twitter_keepalive seconds
		self.twitter_keepalive = 30

		#Add a couple seconds more wait time.
		self.twitter_keepalive += 2.0

		self.sleep_time = 0

		#logging.info('COMPLIANT STREAM: Initializing compliant stream...')

		tweepy.Stream.__init__(self, auth, listener, secure=True, **options) 
开发者ID:bitslabsyr,项目名称:stack,代码行数:27,代码来源:tweetstream.py

示例3: main

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def main(args):
    if args.debug:
        logger.setLevel(logging.DEBUG)

    auth = tweepy.OAuthHandler(args.consumer_key, args.consumer_secret)
    auth.set_access_token(args.access_token, args.access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)
    screen_name = api.me().screen_name

    if args.classifier == 'mock':
        classifier = classifiers.MockClassifier()
    elif args.classifier == 'local':
        classifier = classifiers.URLClassifier(classifiers.ImageClassifier(args.dataset_path, INPUT_SHAPE))
    elif args.classifier == 'remote':
        classifier = classifiers.RemoteClassifier(args.remote_endpoint)

    stream = tweepy.Stream(auth=auth, listener=ReplyToTweet(screen_name, classifier, api, args.silent))
    logger.info('Listening as {}'.format(screen_name))
    stream.userstream(track=[screen_name]) 
开发者ID:AntreasAntoniou,项目名称:DeepClassificationBot,代码行数:21,代码来源:bot.py

示例4: start_stream

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def start_stream(self):
        """Starts a stream with teh current tracking terms"""

        tracking_terms = self.term_checker.tracking_terms()

        if len(tracking_terms) > 0 or self.unfiltered:
            # we have terms to track, so build a new stream
            self.stream = tweepy.Stream(self.auth, self.listener,
                                        stall_warnings=True,
                                        timeout=90,
                                        retry_count=self.retry_count)

            if len(tracking_terms) > 0:
                logger.info("Starting new twitter stream with %s terms:", len(tracking_terms))
                logger.info("  %s", repr(tracking_terms))
                
                # Launch it in a new thread
                self.stream.filter(track=tracking_terms, async=True, languages=self.languages)
            else:
                logger.info("Starting new unfiltered stream")
                self.stream.sample(async=True, languages=self.languages) 
开发者ID:michaelbrooks,项目名称:twitter-monitor,代码行数:23,代码来源:stream.py

示例5: get_streaming_data

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def get_streaming_data(self):
        twitter_stream = Stream(self.auth, twitter_listener(num_tweets_to_grab=self.num_tweets_to_grab, retweet_count = self.retweet_count, stats = self.stats, get_tweet_html = self.get_tweet_html ))
        try:
            twitter_stream.sample()
        except Exception as e:
            print(e.__doc__)

        lang, top_lang, top_tweets = self.stats.get_stats()
        print(Counter(lang))
        print(Counter(top_lang))
        print(len(top_tweets))

        self.c.execute("INSERT INTO lang_data VALUES (?,?, DATETIME('now'))", (str(list(Counter(lang).items())), str(list(Counter(top_lang).items()))))

        for t in top_tweets:
            self.c.execute("INSERT INTO twit_data VALUES (?, DATETIME('now'))", (t,))

        self.conn.commit() 
开发者ID:shantnu,项目名称:TwitterAnalyser,代码行数:20,代码来源:twit1.py

示例6: initialize

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def initialize():
    with open('data/config.json') as config_data:
        config = json.load(config_data)

    auth = tweepy.OAuthHandler(config['consumer_key'], config['consumer_secret'])
    auth.set_access_token(config['access_token'], config['access_token_secret'])
    api = tweepy.API(auth)

    stream = TwitterStreamListener()
    twitter_stream = tweepy.Stream(auth = api.auth, listener=stream)
    twitter_stream.filter(track=['iphone'], async=True) 
开发者ID:amir-rahnama,项目名称:pyspark-twitter-stream-mining,代码行数:13,代码来源:twitter_stream.py

示例7: __init__

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def __init__(self,
                 pipeline,
                 batch_size=1000,
                 consumer_key=settings.CONSUMER_TOKEN,
                 consumer_secret=settings.CONSUMER_SECRET,
                 acces_token=settings.ACCESS_TOKEN,
                 access_secret=settings.ACCESS_SECRET,):
        self.auth = tweepy.OAuthHandler(consumer_key=consumer_key, consumer_secret=consumer_secret)
        self.auth.set_access_token(acces_token, access_secret)
        self.stream = tweepy.Stream(auth=self.auth, listener=Listener(pipeline, batch_size=batch_size))
        logging.basicConfig(filename='log_twitter.txt', level=logging.DEBUG) 
开发者ID:romaintha,项目名称:twitter,代码行数:13,代码来源:streaming_api.py

示例8: _start_user_stream

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def _start_user_stream(self, retweet_replies_to_ids: List[int]):
        auth = self._auth()
        # Setup reply stream for handling mentions and DM
        self._user_stream = tweepy.Stream(auth, TwitterReplyListener(self, self._credentials, retweet_replies_to_ids))
        self._user_stream.userstream(async=True) 
开发者ID:csvance,项目名称:armchair-expert,代码行数:7,代码来源:twitter.py

示例9: get_tweets

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def get_tweets(duik, old_duik):
    this_app = AppOpenLSH.get_or_insert('KeyOpenLSH')
    auth = tweepy.OAuthHandler(this_app.twitter_consumer_key, this_app.twitter_consumer_secret)
    auth.set_access_token(this_app.twitter_access_token_key, this_app.twitter_access_token_secret)
    api = tweepy.API(auth)
    listen = TwitterStatusListener(duik, old_duik, auth)
    stream = tweepy.Stream(auth, listen)

    try:
        stream.sample()
    except tweepy.TweepError:
        logging.error("error with streaming api")
        stream.disconnect()
    return (listen.tweets) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:16,代码来源:read_tweepy.py

示例10: get_tweets

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def get_tweets(users, outfile, stop_num):
    auth, api = login()
    twitter_stream = Stream(auth, MyListener(outfile, stop_num))
    twitter_stream.filter(follow=users, async=True) 
开发者ID:motazsaad,项目名称:tweets-collector,代码行数:6,代码来源:stream_users.py

示例11: get_tweets

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def get_tweets(my_locations, outfile, stop_num):
    auth, api = login()
    twitter_stream = Stream(auth, MyListener(outfile, stop_num))
    # Bounding boxes for geo-locations
    # http://boundingbox.klokantech.com/
    # Online-Tool to create boxes (c+p as raw CSV):
    twitter_stream.filter(locations=my_locations, async=True) 
开发者ID:motazsaad,项目名称:tweets-collector,代码行数:9,代码来源:stream_geolocation.py

示例12: stream_tweets

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def stream_tweets(self, fetched_tweets_filename, hash_tag_list):
        # This handles Twitter authetification and the connection to Twitter Streaming API
        listener = TwitterListener(fetched_tweets_filename)
        auth = self.twitter_autenticator.authenticate_twitter_app() 
        stream = Stream(auth, listener)

        # This line filter Twitter Streams to capture data by the keywords: 
        stream.filter(track=hash_tag_list)


# # # # TWITTER STREAM LISTENER # # # # 
开发者ID:vprusso,项目名称:youtube_tutorials,代码行数:13,代码来源:accessing_published_tweets.py

示例13: stream_tweets

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def stream_tweets(self, fetched_tweets_filename, hash_tag_list):
        # This handles Twitter authetification and the connection to Twitter Streaming API
        listener = StdOutListener(fetched_tweets_filename)
        auth = OAuthHandler(twitter_credentials.CONSUMER_KEY, twitter_credentials.CONSUMER_SECRET)
        auth.set_access_token(twitter_credentials.ACCESS_TOKEN, twitter_credentials.ACCESS_TOKEN_SECRET)
        stream = Stream(auth, listener)

        # This line filter Twitter Streams to capture data by the keywords: 
        stream.filter(track=hash_tag_list)


# # # # TWITTER STREAM LISTENER # # # # 
开发者ID:vprusso,项目名称:youtube_tutorials,代码行数:14,代码来源:tweepy_streamer.py

示例14: initialize_twitter_stream

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def initialize_twitter_stream(self):
        if self.twitter_stream is None:
            self.twitter_stream = tweepy.Stream(self.twitter_auth, self.listener, retry_420=3 * 60) 
开发者ID:pajbot,项目名称:pajbot,代码行数:5,代码来源:twitter.py

示例15: __init__

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Stream [as 别名]
def __init__(self, tweet_callback=lambda x, y, z: x):
		self.tweet_callback = tweet_callback
		
		self.listener = TwitterListener(self.handle_tweet)
		
		self.auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
		self.auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

		self.stream = Stream(self.auth, self.listener)	
		self.stream.filter(follow=FOLLOW_IDS) 
开发者ID:stephancill,项目名称:mcafee2cash,代码行数:12,代码来源:twitter.py


注:本文中的tweepy.Stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。