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


Python Stream.userstream方法代码示例

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


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

示例1: TweepyStreamTests

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import userstream [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: TweepyStreamTests

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import userstream [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

示例3: main

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import userstream [as 别名]
def main():
    logging.info("bot starting")
    bot = Bot()
    logging.info("markov data loading")
    if load_csv == True:
        markov = MarkovGenerator()
        logging.info("load_csv == True")
        csv_tweets = Bot.load_csv_tweets("./tweets.csv")
        #newest_tweet_idを保存
        newest_tweet = csv_tweets.next()
        save_data(newest_tweet[0], "newest_tweet_id")
        markov.add_from_sentence(newest_tweet[7])
        #読み込み
        for tweet in csv_tweets:
            markov.add_from_sentence(tweet)
        markov.save_dictionary()
    else:
        markov = MarkovGenerator(markov_dictionary=load_data("markov_dictionary"), reversed_markov_dictionary=load_data("reversed_markov_dictionary"))
    # 20分ごとの定期ツイート
    #multiprocess間での値のやり取り用変数
    logging.info("regular tweet starting")
    p = Process(target=regular_tweet, args=(bot, markov))
    p.start()
    # userstreamによるTL監視(リプライ・ふぁぼ・パクツイ・RT)
    logging.info("start timeline watching")
    stream = Stream(bot.auth, AbstractedlyListener(), secure=True)
    user_stream = stream.userstream()
    user_stream.start()
开发者ID:airtoxin,项目名称:twitterbot,代码行数:30,代码来源:bot.py

示例4: TweepyStreamTests

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import userstream [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

示例5: Crawler

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import userstream [as 别名]
class Crawler():
    ''' The global crawler manager '''

    def __init__(self, name):
        self.name = name
        self.regexp = re.compile(r'@%s\s+' % (self.name),
                                 re.IGNORECASE)

        self._start_stream()


    def _auth(self):
        self.auth = OAuthHandler(Ukey, Usecret)
        self.auth.set_access_token(Akey, Asecret)

        self.api = API(self.auth)

    def _start_stream(self):
        self.listener = Streamer(self)

        self._auth()

        self.stream = Stream(self.auth, self.listener)
        self.stream.userstream()

    def on_request(self, text, author):
        text = re.sub(self.regexp, '', text)
        text = re.sub(r'\s+$', '', text)

        lang = get_language(text, key=u'startword')

        if lang is not None:
            core = Core(lang)
            self.send_message(core.send_message(), author)

    def send_message(self, text, target=None):

        if(target is not None):
            text = u'@%s %s' % (target, text)

        print(text)
        print '>>>', len(text)
        self.api.update_status(text)
开发者ID:Swizz,项目名称:UnnamedGame,代码行数:45,代码来源:crawler.py

示例6: ReloadOutputFiles

# 需要导入模块: from tweepy.streaming import Stream [as 别名]
# 或者: from tweepy.streaming.Stream import userstream [as 别名]
	self.output_filenames = output_filenames
	self.OpenOutputFiles()

    def ReloadOutputFiles(self):
	self.CloseOutputFiles()
	self.OpenOutputFiles()

    """ Let's stare abstractedly at the User Streams ! """
    def on_status(self, status):
	dump_text = json.dumps(status._json) + "\n"
	if self.output_files is None:
		print dump_text
		sys.stdout.flush()
		return
	for file in self.output_files:
		file.write(dump_text)
		file.flush()

listener = Listener()

def SigHupHandler(signum, frame):
	listener.ReloadOutputFiles()

if __name__ == '__main__':
    signal.signal(signal.SIGHUP, SigHupHandler)
    auth = get_oauth()
    listener.SetOutputFilenames(sys.argv[1:])
    stream = Stream(auth, listener, secure=True)
    daemon.daemonize(PID_FILE_NAME)
    stream.userstream()
开发者ID:necoma,项目名称:matatabi_script,代码行数:32,代码来源:TwitterStreamingWatcher.py


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