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


Python Stream.filter方法代码示例

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


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

示例1: TweepyStreamTests

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
class TweepyStreamTests(unittest.TestCase):
    def setUp(self):
        self.auth = create_auth()
        self.listener = MockStreamListener(self)
        self.stream = Stream(self.auth, self.listener, timeout=3.0)

    def tearDown(self):
        self.stream.disconnect()

    def test_userstream(self):
        # Generate random tweet which should show up in the stream.
        def on_connect():
            API(self.auth).update_status(mock_tweet())

        self.listener.connect_cb = on_connect
        self.listener.status_stop_count = 1
        self.stream.userstream()
        self.assertEqual(self.listener.status_count, 1)

    def test_sample(self):
        self.listener.status_stop_count = 10
        self.stream.sample()
        self.assertEquals(self.listener.status_count,
                          self.listener.status_stop_count)

    def test_filter_track(self):
        self.listener.status_stop_count = 5
        phrases = ['twitter']
        self.stream.filter(track=phrases)
        self.assertEquals(self.listener.status_count,
                          self.listener.status_stop_count)
开发者ID:dowens,项目名称:tweepy,代码行数:33,代码来源:test_streaming.py

示例2: test_track_encoding

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
    def test_track_encoding(self):
        s = Stream(None, None)
        s._start = lambda is_async: None
        s.filter(track=[u'Caf\xe9'])

        # Should be UTF-8 encoded
        self.assertEqual(u'Caf\xe9'.encode('utf8'), s.body['track'])
开发者ID:tweepy,项目名称:tweepy,代码行数:9,代码来源:test_streaming.py

示例3: filter_track

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def filter_track(follow):
    auth = OAuthHandler(consumer_key2, consumer_secret2)
    auth.set_access_token(access_token2, access_token_secret2)
    stream = Stream(auth, MyStreamListener())
    api = API(auth)
    #print 'start filter track ', ','.join(track)
    stream.filter(track=follow)
开发者ID:LookThisCode,项目名称:NextLevelLatAm,代码行数:9,代码来源:twitter_polling.py

示例4: test_follow_encoding

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
    def test_follow_encoding(self):
        s = Stream(None, None)
        s._start = lambda async: None
        s.filter(follow=[u'Caf\xe9'])

        # Should be UTF-8 encoded
        self.assertEqual(u'Caf\xe9'.encode('utf8'), s.session.params['follow'])
开发者ID:GoNexia,项目名称:tweepy,代码行数:9,代码来源:test_streaming.py

示例5: IRCPlugin

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
class IRCPlugin(BasePlugin):
    name = "twitter_stream"
    enabled = True

    def _validate(self, event):
        return False

    def stop(self):
        if self._stream:
            self._stream.disconnect()

    def run(self):
        try:
            auth = tweepy.OAuthHandler(config.TWITTER_CONSUMER_KEY, config.TWITTER_CONSUMER_SECRET)
            auth.set_access_token(config.TWITTER_ACCESS_KEY, config.TWITTER_ACCESS_SECRET)
            self._stream = Stream(auth, StreamerToIrc(self))
            LOG.info("Twitter stream successfully initializing")
        except Exception as e:
            LOG.error("Twitter stream authorization failed: %s" % e)
            return
        followers = []
        api = API(auth)
        for f in config.TWITTER_FOLLOW_IDS:
            if isinstance(f, (str, unicode)):
                try:
                    user_id = api.get_user(f).id
                    followers.append(str(user_id))
                except Exception:
                    LOG.debug("Can't get ID for %s" % user_id)
                    continue
            else:
                followers.append(str(f))
        self._stream.filter(followers)
开发者ID:gigimon,项目名称:thpybotter,代码行数:35,代码来源:irc_twi_stream.py

示例6: get_tweets

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def get_tweets(keyword):
        init_tweepy()
	auth = tweepy.OAuthHandler('QxpECDyg9eM6inD0jo7Q','a0A8OE2ZN7imCg6WR5ygkrGvKG6tNtoZIChQXQ8NIf4')
	auth.set_access_token('18752311-FXmc9zaPGcszH1bdDNJQa0MY2XRYfYzT3nBRnMqgB','tzXURgYPAbsD1VgmchkoKH9QOJ80qGgSSL13K5A3rY')
	api = tweepy.API(auth)
	listener = Listener()
	stream = Stream(auth, listener)
	stream.filter(track=[keyword])
开发者ID:mguarascio,项目名称:candidatefeed,代码行数:10,代码来源:listener.py

示例7: filter_track

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def filter_track():
    q = Scrapers.all().filter('','')
    follow=[s.uid for s in q]
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, MyStreamListener())
    api = API(auth)
    #print 'start filter track ', ','.join(track)
    stream.filter(follow=follow)
开发者ID:LookThisCode,项目名称:NextLevelLatAm,代码行数:11,代码来源:twitter_polling.py

示例8: TweepyStreamTests

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
class TweepyStreamTests(unittest.TestCase):
    def setUp(self):
        self.auth = create_auth()
        self.listener = MockStreamListener(self)
        self.stream = Stream(self.auth, self.listener, timeout=3.0)

    def tearDown(self):
        self.stream.disconnect()

    def test_userstream(self):
        # Generate random tweet which should show up in the stream.
        def on_connect():
            API(self.auth).update_status(mock_tweet())

        self.listener.connect_cb = on_connect
        self.listener.status_stop_count = 1
        self.stream.userstream()
        self.assertEqual(self.listener.status_count, 1)

    def test_userstream_with_params(self):
        # Generate random tweet which should show up in the stream.
        def on_connect():
            API(self.auth).update_status(mock_tweet())

        self.listener.connect_cb = on_connect
        self.listener.status_stop_count = 1
        self.stream.userstream(_with='user', replies='all', stall_warnings=True)
        self.assertEqual(self.listener.status_count, 1)

    def test_sample(self):
        self.listener.status_stop_count = 10
        self.stream.sample()
        self.assertEquals(self.listener.status_count,
                          self.listener.status_stop_count)

    def test_filter_track(self):
        self.listener.status_stop_count = 5
        phrases = ['twitter']
        self.stream.filter(track=phrases)
        self.assertEquals(self.listener.status_count,
                          self.listener.status_stop_count)

    def test_track_encoding(self):
        s = Stream(None, None)
        s._start = lambda async: None
        s.filter(track=[u'Caf\xe9'])

        # Should be UTF-8 encoded
        self.assertEqual(u'Caf\xe9'.encode('utf8'), s.parameters['track'])

    def test_follow_encoding(self):
        s = Stream(None, None)
        s._start = lambda async: None
        s.filter(follow=[u'Caf\xe9'])

        # Should be UTF-8 encoded
        self.assertEqual(u'Caf\xe9'.encode('utf8'), s.parameters['follow'])
开发者ID:bakagh,项目名称:tweepy,代码行数:59,代码来源:test_streaming.py

示例9: main_logger

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def main_logger(basename=None):
        l = RotatingLogListener(basename=basename)
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        stream = Stream(auth, l)

        # This fetches ANY geotagged tweet:
        # https://dev.twitter.com/docs/streaming-apis/parameters#locations
        stream.filter(locations=[-180,-90,180,90])
开发者ID:chebee7i,项目名称:twitter,代码行数:11,代码来源:stream.py

示例10: train_tweets

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def train_tweets():
    tokyo    = LocationFence("Tokyo",    138.946381, 35.523285, 139.953232, 35.906849)
    hokkaido = LocationFence("Hokkaido", 139.546509, 41.393294, 145.742798, 45.729191)
    kyusyu   = LocationFence("Kyusyu",   129.538879, 31.147006, 131.856995, 33.934245)

    locations = [tokyo, hokkaido, kyusyu]
    request_coordinates = []
    for l in locations:
        request_coordinates += l.get_coordinates()

    stream = Stream(oauth(), Trainer(locations), secure=True)
    stream.filter(locations=request_coordinates)
开发者ID:isaac-gritz,项目名称:jubatus-example,代码行数:14,代码来源:train.py

示例11: main

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def main():
  try:
    config = get_twitter_config(CONFIG_FILE, TWITTER_SCREEN_NAME)
    auth = tweepy.OAuthHandler(config['consumer_key'], config['consumer_secret'])
    auth.set_access_token(config['access_key'], config['access_secret'])
#    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
#    auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
    listener = Listener()
    stream = Stream(auth, listener, timeout=None,secure=1)
    #stream = Stream(USERNAME, PASSWORD, listener, timeout=None)
    # sample returns all tweets

    stream.filter(track = KEYWORDS)
  except KeyboardInterrupt:
    print '\nGoodbye!'
开发者ID:neilkod,项目名称:raindrop,代码行数:17,代码来源:raindrop.py

示例12: __listen

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
    def __listen(self):
        listener = TweetStreamListener(self.api, self.sentiment, self.error)
        stream = Stream(self.auth, listener)

        print 'Starting stream...'
        try:
            stream.filter(track=self.track)
        except:
            print 'Encountered error!'
            print 'Exiting application'
            item = {
                    'status'    : 'stream down',
                    'timestamp' : datetime.utcnow()
                   }
            self.error.save(item)
            stream.disconnect()
开发者ID:bedouins,项目名称:TweetIndex,代码行数:18,代码来源:main.py

示例13: TweepyStreamTests

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
class TweepyStreamTests(unittest.TestCase):
    def setUp(self):
        self.auth = create_auth()
        self.listener = MockStreamListener(self)
        self.stream = Stream(self.auth, self.listener, timeout=3.0)

    def tearDown(self):
        self.stream.disconnect()

    def test_userstream(self):
        # Generate random tweet which should show up in the stream.
        def on_connect():
            API(self.auth).update_status(mock_tweet())

        self.listener.connect_cb = on_connect
        self.listener.status_stop_count = 1
        self.stream.userstream()
        self.assertEqual(self.listener.status_count, 1)

    def test_sample(self):
        self.listener.status_stop_count = 10
        self.stream.sample()
        self.assertEquals(self.listener.status_count,
                          self.listener.status_stop_count)

    def test_filter_track(self):
        self.listener.status_stop_count = 5
        phrases = ['twitter']
        self.stream.filter(track=phrases)
        self.assertEquals(self.listener.status_count,
                          self.listener.status_stop_count)

    def test_on_data(self):        
        test_wrong_data = [
            '{"disc', # this is actual data read from twitter
            '600',    # this is actual data read from twitter
            '41\n',   # this is actual data read from twitter
            'obviously non-json',
            '"json but not dict"',
			'{"json dict":"but not a twitter message"}'
        ]        
        for raw_data in test_wrong_data: 
            # should log errors but not raise / not return False
            self.assertEquals(self.listener.on_data(raw_data), None)
            self.assertEquals(self.listener.status_count, 0)
开发者ID:mandelcode,项目名称:tweepy,代码行数:47,代码来源:test_streaming.py

示例14: StreamsTestsPlain

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
class StreamsTestsPlain(object):
    
    def __init__(self):
        self._stream = None
        self._oauth = None
        self._oauth_api = None
        
        self._stream_init()
        self._oauth_init()
        
    def _oauth_init(self):
        self._oauth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET)
        self._oauth.set_access_token(social_keys.TWITTER_APP_ACCESS_TOKEN,social_keys.TWITTER_APP_ACCESS_TOKEN_SECRET)
        self._oauth_api = API(self._oauth)
    
    def _stream_init(self):
        api1 = API()
        
        headers = {}
        headers["Accept-Encoding"] = "deflate, gzip"
        stream_auth = BasicAuthHandler(social_keys.TWITTER_HTTP_AUTH_U,social_keys.TWITTER_HTTP_AUTH_P)
        
        l = TestStreamListener(api=api1)
        self._stream = Stream(auth=stream_auth,listener=l,secure=True,headers=headers)
    
    def sample(self):
        self._stream.sample()
        
    def filter_follow(self):
        follow_names = ['hnfirehose','StockTwits','YahooFinance','Street_Insider','TheStreet','SquawkCNBC','CNBC','AP_PersonalFin','themotleyfool','MarketWatch','Reuters_Biz']
        follow_usr_objs = self._oauth_api.lookup_users(screen_names=follow_names)
        follow_ids = []
        
        for follow_usr in follow_usr_objs:
            follow_ids.append(follow_usr.id)
        
        print follow_ids
        
        self._stream.filter(follow=follow_ids)
    
    def filter(self):
        self._stream.filter(track=["@newsdotme","@twixmit","@app_engine"])
开发者ID:twixmit,项目名称:twixmit,代码行数:44,代码来源:streamstest.py

示例15: main

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import filter [as 别名]
def main():
    try:
        parser = ArgumentParser()
        parser.add_argument("oauth_keys_file",
                        help="The location of a file containing the application " +
                        "oath consumer key, consumer secret, " +
                        "access token, and access token secret, " +
                        "each on its own line, in that order.  " +
                        "See the tweepy example on oauth to figure " +
                        "out how to get these keys."
                        )
        parser.add_argument("mail_settings_file", help="The automail settings file for sending emails.")
        args = parser.parse_args()
        (consumer_key, consumer_secret, access_token, access_token_secret) = \
            parse_oauth_file(args.oauth_keys_file)
    
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
    
        pl = PaxListener(args.mail_settings_file, auth)
        
        #open a stream, with ourself as the listener
        stream = Stream(auth, pl)
        #stream.filter(track=["the"])
    
        pax_user_id = '26281970' #follow requires userid, found at mytwitterid.com
        daemon_user_id = '1954653840'
        stream.filter(follow=[pax_user_id]) #track ignores follow, pulls from firehose regardless (this is testing acct)

    except BaseException as e:
        subject = "Exception from paxtix"
        exc_type, exc_value, exc_traceback = sys.exc_info()
        message = '\n'.join(["Pax tix listener has hit an exception!",] + 
                             traceback.format_exception(exc_type, exc_value, exc_traceback),
                             )
        send_email(parse_settings(args.mail_settings_file), subject, message)
        traceback.print_exception(exc_type, exc_value, exc_traceback)
开发者ID:CarlLooksUp,项目名称:paxtix,代码行数:39,代码来源:paxtix.py


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