users.py 文件源码

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

项目:python-twitter-toolbox 作者: hhromic 项目源码 文件源码
def get_hydrated(writer, user_ids=None, screen_names=None):
    """Get hydrated Twitter User-objects from a list of user ids and/or screen names."""
    LOGGER.info("get_hydrated() starting")
    ensure_at_least_one(user_ids=user_ids, screen_names=screen_names)
    user_ids = user_ids if user_ids else []
    screen_names = screen_names if screen_names else []

    # initialize config and Twitter API
    config = read_config()
    api = get_oauth_api(config)  # OAuth gives more capacity for the users/lookup API

    # process user ids and/or screen names, storing returned users in JSON format
    num_users = 0
    for chunk in gen_chunks(user_ids, screen_names, size=LOOKUP_USERS_PER_REQUEST):
        try:
            num_users += write_objs(writer, api.lookup_users,
                                    {"user_ids": chunk[0], "screen_names": chunk[1]})
        except TweepError as err:
            log_tweep_error(LOGGER, err)
    LOGGER.info("downloaded %d user(s)", num_users)

    # finished
    LOGGER.info("get_hydrated() finished")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号