简体   繁体   中英

How to get latest repository through GitHub API with Python?

I would like to create app, that will show lately updated repository at somebody's (organisation) GitHub account.
I tried PyGitHub, I tried json in many ways (with parameters, different iterations, relating to keys) but with no result.

Can somebody help?

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'])

You can call the updated_at method on a repository and store the date for a comparison the next time you check if the repo was updated.

Getting the date of the last update:

from github import Github

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

date = 2017-05-02 13:48:58

then you just need to:
1. store the date associated with the repository
2. call the function once every X hours or whatever interval you choose.
3. then compare the stored date with the new date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM