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


Python Collector.search方法代码示例

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


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

示例1: main

# 需要导入模块: from collector import Collector [as 别名]
# 或者: from collector.Collector import search [as 别名]
def main():
    creds = Credentials(os.path.expanduser('~/.tweepy'))
    today = datetime.date.today()
    week = datetime.timedelta(7)
    query_terms=['#NBAFinals2015', '#Warriors'] 
    query_ops={}
    query_ops['lang'] = 'en'
    stream = False;
    if stream:
        auth = tweepy.OAuthHandler(creds.consumer_key, creds.consumer_secret)
        auth.set_access_token(creds.access_token, creds.access_token_secret)
        query_ops['until'] = today+week
    else:
        #Per Ron Cordell's suggestion, use App Auth token for increased limits
        auth = tweepy.AppAuthHandler(creds.consumer_key, creds.consumer_secret)
        query_ops['since'] = today-week
        query_ops['until'] = today
        query_ops['result_type'] = 'recent'
    collector = Collector(auth)
    if stream:
        print("Starting streaming")
        collector.stream(query_terms=query_terms,
                  query_ops=query_ops)
    else:
        print("Starting search")
        collector.search(query_terms=query_terms,
                  query_ops=query_ops)
    print('All done!  Last ID processed={0}'.format(collector.last_id))
开发者ID:nkrishnaswami,项目名称:mids-w205-hw2,代码行数:30,代码来源:acq.py

示例2: main

# 需要导入模块: from collector import Collector [as 别名]
# 或者: from collector.Collector import search [as 别名]
def main():
    query_terms=['#NBAFinals2015', '#Warriors']
    # We only need a single mongodb sink; FilteringFacet will just let us
    # avoid storing non-matching tweets
    sink = MongoDBSink('db_restT')
    sink.open('tweets')
    # closing ensures any files written get flushed/closed.
    with closing(
            FilteringFacet(
                RegexMatcher('(' + '|'.join(query_terms) + ')'),
                lambda key: sink)) as facet:
        creds = Credentials(os.path.expanduser('~/.tweepy'))
        auth = tweepy.AppAuthHandler(creds.consumer_key, creds.consumer_secret)
        collector = Collector(auth, facet)
        
        today = datetime.date.today()
        week = datetime.timedelta(7)

        query_ops={}
        query_ops['lang'] = 'en'
        query_ops['result_type'] = 'mixed'
        
        print("Starting search")
        collector.search(query_terms=query_terms,
                         query_ops=query_ops)
        print('All done!  Last ID processed={0}'.format(collector.last_id))
开发者ID:nkrishnaswami,项目名称:mids-w205-hw3,代码行数:28,代码来源:1.1_acq.py


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