Github API,获取用 Python 语言编写的最受好评的公共存储库

Ace*_*.py 8 python api github pandas

我正在试验 Python。我想实现的是使用 Github API,我想获取自上个月以来用 Python 语言编写并创建的前 10 位最受好评的公共存储库。谁能给我一些关于如何实现这一目标的提示?

到目前为止,我已成功实现以下目标:

import pandas as pd
import requests 
from datetime import datetime
df = pd.DataFrame(columns=['repository_ID', 'name', 'URL', 'created_date',  'description', 'number_of_stars'])
results = requests.get('https://api.github.com/search/repositories?q=language:python&sort=stars&order=desc').json()

for repo in results['items']:
        d_tmp = {'repository_ID': repo['id'],
                'name': repo['name'],
                'URL': repo['html_url'],
                'created_date': datetime.strptime(repo['created_at'], '%Y-%m-%dT%H:%M:%SZ'),


                'number_of_stars': repo['stargazers_count']}
        df = df.append(d_tmp, ignore_index=True)


print d_tmp
Run Code Online (Sandbox Code Playgroud)

这给了我以下按星降序排列的观看次数最多的结果:

{'URL': u'https://github.com/faif/python-patterns', 'repository_ID': 4578002, 'number_of_stars': 18103, 'name': u'python-patterns', 'created_date': datetime.datetime(2012, 6, 6, 21, 2, 35)}
Run Code Online (Sandbox Code Playgroud)

我坚持的是: 如何在过去两个月和前 10 个存储库中获得相同的结果? 我感谢所有有价值的信息。

Ped*_*ges 4

可以使用createdgithub api的参数。因此,要获取自第 9 个月以来按星级排序的 python 存储库,您可以执行以下请求。

https://api.github.com/search/repositories?q=created:">2018-09-30"language:python&sort=stars&order=desc
Run Code Online (Sandbox Code Playgroud)

然后要获取前 10 个存储库,您可以执行以下操作:

top_ten = results['items'][0:10]
Run Code Online (Sandbox Code Playgroud)

如果您想限制 api 调用返回的项目数,可以使用该per_page=10参数。下面的查询与上面的查询相同,但仅返回 10 个结果。

https://api.github.com/search/repositories?q=created:">2018-09-30"language:python&sort=stars&order=desc&per_page=10
Run Code Online (Sandbox Code Playgroud)

祝您的项目好运!