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


Python twitter.TwitterStream方法代码示例

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


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

示例1: run_sample

# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import TwitterStream [as 别名]
def run_sample(self):
        """
        Listen to live data from Twitter, and pass on the fully-formed tweets
        to `check_ftfy`. This requires the `twitter` Python package as a
        dependency.
        """
        from twitter import TwitterStream
        from ftfy.streamtester.oauth import get_auth
        twitter_stream = TwitterStream(auth=get_auth())
        iterator = twitter_stream.statuses.sample()
        for tweet in iterator:
            if 'text' in tweet:
                self.check_ftfy(tweet['text'])
                if 'user' in tweet:
                    lang = tweet['user'].get('lang', 'NONE')
                    self.lines_by_lang[lang].append(tweet['text'])
                if self.count % 10000 == 100:
                    self.save_files() 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:20,代码来源:twitter_tester.py

示例2: streamAPI

# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import TwitterStream [as 别名]
def streamAPI():
    try:
#         q = 'uga'
#        locations = "-83.40,33.93,-83.37,33.94 "
        locations = "-84.56,33.62,-84.20,33.91"
        
#         print >> sys.stderr,'Filtering the public timeline for track = "%s"' %(q)
        
        
        
        twitter_stream = twitter.TwitterStream(auth = twitter_api.auth)
#        print twitter_stream
        
        stream = twitter_stream.statuses.filter(locations = locations)
#        print stream

        InsertStatus(stream)

        


        
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        print ''.join('!! ' + line for line in lines)  # Log it or whatever here
        logger.info(''.join('!! ' + line for line in lines) ) 
开发者ID:xbwei,项目名称:Data-Mining-on-Social-Media,代码行数:29,代码来源:StreamAPI.py

示例3: stream_data

# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import TwitterStream [as 别名]
def stream_data(self, track=None, follow=None, locations=None, save_to_db=False,
                    collection_name='stream'):
        """
            https://dev.twitter.com/streaming/reference/post/statuses/filter
            The default access level allows up to 400 track keywords, 5,000 follow userids and 25 0.1-360 degree location boxes.

        :param track: str    ;
        :param follow:list str ;
        :param locations: str ;
        :param save_to_db:
        :param collection_name:
        :return: None
        """

        def location_bounding_box(_locations):
            t = _locations.split(',')
            res = ''
            for i in xrange(0, len(t), 2):
                x, y = str(float(t[i]) + 1), str(float(t[i + 1]) + 1)
                res += t[i] + ',' + t[i + 1] + ',' + x + ',' + y + ','
            return res

        kwg = {'language': 'en'}

        if not track and not follow and not locations:
            kwg['track'] = 'twitter'

        if track:
            kwg['track'] = track

        if follow:
            kwg['follow'] = follow

        if locations:
            kwg['locations'] = location_bounding_box(locations)

        print kwg

        twitter_stream = twitter.TwitterStream(auth=self.twitter_api.auth)
        stream = twitter_stream.statuses.filter(**kwg)

        for i, tweet in enumerate(stream):
            if not i % 200 and 'text' in tweet: print i, datetime.datetime.now(), ' ', tweet["text"]
            tweet = dict(tweet)
            if 'id' in tweet:
                self.tweets.append(tweet)

                if self.get_data:
                    self.get_data = False
                    self.conn.send(self.tweets)
                    self.tweets = []

                if save_to_db:
                    self.save_tweets_to_mongodb(tweet, colname=collection_name) 
开发者ID:hrwhisper,项目名称:twitterDataMining,代码行数:56,代码来源:Stream.py


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