__main__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:hoottit 作者: Owlree 项目源码 文件源码
def main():
    """This is the main entry point. Here we launch the threads that stream
    submissions and comments to the database
    """
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s @ %(threadName)s -- %(module)s.'
                        '%(funcName)s -- [%(levelname)s] %(message)s')

    # parse arguments
    parser = _get_parser()
    args = vars(parser.parse_args())

    # get configuration variables
    config = _get_config(args['config'])
    sentry = config.get('sentry', None)
    mongo_uri = _get_env_or_config(config, 'mongo')
    subs = config.get('subreddits')
    credentials = config.get('credentials')

    # initialize sentry client
    if sentry is not None:
        raven.Client(sentry)
        logging.info('Sentry client initialized.')

    # initialize database
    client = pymongo.MongoClient(mongo_uri)
    database = client.get_default_database()
    hoottit.util.initialize_indexes(database)

    # fire streaming processes
    pool = multiprocessing.dummy.Pool(2)
    pool.map(hoottit.util.execute, (
        hoottit.util.pipe(
            getattr(hoottit.producers, p)(subs, credentials.get(p)),
            hoottit.consumers.mongo_upsert(database[p],
                                           'reddit_id',
                                           args['log_threshold'])
        ) for p in ['comments', 'submissions'] if args[p]))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号