【问题标题】:How to get latest repository through GitHub API with Python?如何使用 Python 通过 GitHub API 获取最新的存储库?
【发布时间】:2017-05-02 14:08:28
【问题描述】:

我想创建一个应用程序,它将在某人(组织)的 GitHub 帐户中显示最近更新的存储库。
我尝试了 PyGitHub,我以多种方式尝试了 json(使用参数、不同的迭代、与键相关),但没有结果。

有人可以帮忙吗?

from github import Github
import requests
import json

parameters = {"sort": 'pushed'}
r = requests.get("https://api.github.com/users/:github_user_name:/repos.json", params=parameters)   

resp = r.json()

for item in resp['updated_at']:
    print(item['updated_at'])

【问题讨论】:

    标签: python api github


    【解决方案1】:

    您可以在存储库上调用updated_at 方法并存储日期,以便下次检查存储库是否已更新时进行比较。

    获取上次更新的日期:

    from github import Github
    
    g = Github('username', 'password')
    repo = g.get_repo('CouchPotato/CouchPotatoServer')  # full repo name or id
    date = repo.updated_at
    

    日期 = 2017-05-02 13:48:58

    那么你只需要:
    1.存储与存储库关联的日期
    2. 每 X 小时或您选择的任何间隔调用一次该函数。
    3.然后将存储的日期与新的日期进行比较。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      相关资源
      最近更新 更多