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


Python Author.load方法代码示例

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


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

示例1: fetch

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import load [as 别名]
def fetch():
    sys.stdout.write('loading')
    sys.stdout.flush()
    repos = Repo.load_sample()
    authors = {author.login: author for author in Author.load(FILE)}

    seen = 0
    total = len(repos)
    failures = []
    last_write = datetime.datetime.now()

    el = Elaborator()

    for repo in repos:
        seen += 1

        if repo.username in authors:
            logging.info("already fetched %s", repo.username)
            continue

        try:
            gh_data = el._gh_request(
                'GET',
                '/users/' + repo.username
            )
        except:
            #loop really needs to keep running
            logging.exception("problem! %s", repo)
            failures.append(repo)
            continue

        authors[repo.username] = Author(**{key: gh_data.get(key, None) for key in
                                           ['login',  # "octocat"
                                            'id',  # 1
                                            'avatar_url',  # "https://github.com/images/error/octocat_happy.gif"
                                            'gravatar_id',  # "somehexcode"
                                            'url',  # "https://api.github.com/users/octocat"
                                            'name',  # "monalisa octocat"
                                            'company',  # "GitHub"
                                            'blog',  # "https://github.com/blog"
                                            'location',  # "San Francisco"
                                            'email',  # "[email protected]"
                                            'hireable',  # false
                                            'bio',  # "There once was..."
                                            'public_repos',  # 2
                                            'public_gists',  # 1
                                            'followers',  # 20
                                            'following',  # 0
                                            'html_url',  # "https://github.com/octocat"
                                            'created_at',  # "2008-01-14T04:33:35Z"
                                            'type',  # "User"
                                            ]})

        logging.info("fetched %s", repo.username)

        progress_bar(seen, total)

        since_write = datetime.datetime.now() - last_write

        if since_write > datetime.timedelta(minutes=5):
            sys.stdout.write("\r(writing results)")
            sys.stdout.flush()
            Author.dump(authors.values(), FILE)

            last_write = datetime.datetime.now()

    print  # from progress bar line

    if failures:
        print "%s failures:" % len(failures)
        for f in failures:
            print "  %s" % f
        print

    print 'writing out...'
    Author.dump(authors.values(), FILE)
开发者ID:simon-weber,项目名称:Predicting-Code-Popularity,代码行数:78,代码来源:fetch_author_info.py


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