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


Python Stream.run方法代码示例

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


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

示例1: start

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import run [as 别名]
    def start(self, users):
        print "Starting..."
        #start Twitter stream
        streamThreads  = []
        streamBuffers  = []
        
        for user in users:
            sr = Stream(user['con_key'], user['con_secret'], 
                        user['key'], user['secret'], 
                        user['name'])
            
            #insert user list into db
            list = sr.getUserList(self.parseLists(user['lists']))
            
            self.sql.insert_into_userList(list, user['db'])
            
            #get buffer and run stream
            buff = sr.getTweetsBuffer()
	    if list is not None:
            	stream = sr.run(list)
	    else:
		  stream = sr.run(None)
            #add new buff and stream to list
            streamBuffers.append({'buff':buff, 'db':user['db']})
            streamThreads.append(stream)
            print "Started user: " + user['name']
            self.logger.info("Started user: " + user['name'])

        while True:
            try:
                for buffer in streamBuffers:
                    tweet = buffer['buff'].pop()
                    if not tweet:
                        time.sleep(1)
                    else:
                        self.sql.insert_into(buffer['db'], tweet)
            except KeyboardInterrupt:
                print "Exiting..."
                os._exit(0)
开发者ID:SonicBob12,项目名称:pyTwitterCollector,代码行数:41,代码来源:Collector.py

示例2: start

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import run [as 别名]
    def start(self, users):
        #users is a list of dictionary type objects
        # dict type objects from getConfig()
        print "Starting..."
        #start Twitter stream
        streamThreads  = []
        streamBuffers  = []
        
        for user in users:
            sr = Stream(user['con_key'], user['con_secret'], 
                        user['key'], user['secret'], 
                        user['name'])
            
            #insert user list into db
            list = sr.getUserList(self.parseLists(user['lists']))
            self.sql.insert_into_userList(list, user['db'])
            
            track = []
            for keyword in user['track'].split(','):
                track.append(keyword)
            
            #get buffer and run stream
            buff = sr.getTweetsBuffer()
# 	    if list is not None or track is not None:
#                 stream = sr.run(list, track)
# 	    else:
# 		  stream = sr.run(None)
            stream = sr.run(list, track)
            #add new buff and stream to list
            streamBuffers.append({'buff':buff, 'db':user['db']})
            streamThreads.append(stream)
            print "Started user: " + user['name']
            self.logger.info("Started user: " + user['name'])

        while True:
            try:
                for buffer in streamBuffers:
                    tweet = buffer['buff'].pop()
                    if not tweet:
                        time.sleep(1)
                    else:
                        self.sql.insert_into(buffer['db'], tweet)
            except KeyboardInterrupt:
                print "Exiting..."
                os._exit(0)
开发者ID:bikashmishra,项目名称:TwitterAnalysis,代码行数:47,代码来源:Collector.py


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