python - 获取所有 github 用户详细信息

标签 python github github-api github3.py

我想获取 github 用户及其位置。我知道有 Github apI(GET/users) 可以为我提供用户列表。目前我正在使用PyGithub访问 github 但似乎这个库还没有实现这个 API。谁能建议我如何使用任何 github API 库获取 github 用户及其位置?

编辑1: 我更新了代码如下。但有些我无法获取电子邮件 ID 和位置。

import github3
from datetime import datetime

def main():
        g = github3.login(username="rakeshcusat", password="mypassword")
    for user in g.iter_emails():
        print user
    current_time = datetime.now()   
    fhandler = open("githubuser_"+current_time.strftime("%d-%m-%y-%H:%M:%S"), "w")

    for user in g.iter_all_users():
            fhandler.write(" user: {0}, email: {1}, location: {2}\n".format(user, user.email, user.location))
            #fhandler.flush()

    fhandler.close()        

if __name__ == "__main__":
    main()

示例输出

 user: andywatts, email: None, location: 
 user: mueller, email: None, location: 
 user: cp, email: None, location: 
 user: davea, email: None, location: 
 user: vrieskist, email: None, location: 

最佳答案

github3 library支持对所有用户进行迭代:

import github3

for user in github3.iter_all_users():
    user.refresh()
    print user.location

github3.iter_all_users()产生User objects .

您需要在此处调用 .refresh(),因为 /users endpoint仅返回用户信息的较小子集,并且位置不包含在其中。这需要另一个 API 请求,因此您可能需要调整脚本的速度以避免达到 GitHub 速率限制。

future 版本的 github3(高于 0.7.0)添加了对指定页面(批量)大小的支持,以减少您需要发出的 API 请求的数量; GitHub API 默认为每页 30 个结果,但允许您load up to 100 results per page相反:

for user in github3.iter_all_users(per_page=100):
    user.refresh()
    print user.location

关于python - 获取所有 github 用户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17128654/

相关文章:

python - 为什么关闭数据库连接需要 teardown_appcontext?

android - 尽管删除 git 子模块仍出现 "detached HEAD"错误

python - 在多标题数据框中选择一列

python - 为什么我的代码 'next()' 函数在这个例子中没有被调用?

github 用户 API 分页不起作用

php - 多个程序员如何使用 Laravel 和 GitHub?

github - 如何仅从 GitHub 的 API 获取问题

api - GitHub API : get billing quota reset date

curl - 如何使用带有 curl 的 GitHub API v3 创建和发布版本?

python - 从 Python 程序获取 WinWord 版本