python - Github API,获取用 Python 语言编写的最高星级公共存储库
问题描述
我正在尝试使用 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
这给了我以下按星数降序排序的观看次数最多的结果:
{'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)}
我坚持的是: 如何在过去两个月和前 10 个存储库中获得相同的结果? 我感谢所有有价值的信息。
解决方案
您可以使用created
github api 的参数。因此,要获取自第 9 个月以来按星号排序的 python 存储库,您可以执行以下请求。
https://api.github.com/search/repositories?q=created:">2018-09-30"language:python&sort=stars&order=desc
然后要获得前 10 个回购协议,您可以执行以下操作:
top_ten = results['items'][0:10]
如果要限制 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
祝你的项目好运!
推荐阅读
- spring-boot - Sleuth 显示不正确的 traceId
- python - 包括 QStackedLayout 会打乱布局
- python - 双重问题解决后的支持向量机偏差太大了
- javascript - 如何实现对象数组的接口?
- sql-server - 从 SQL Server 中的 XML 列获取数据
- javascript - 尝试将对象添加到数组时出现意外结果
- jetbrains-ide - 在 JetBrains IDE 中进行 linting 时忽略 yaml 文件
- python - Floyd-Warshall 最多有 k 个边
- c# - 如何在调用 display() 时摆脱 namespace.Classname?
- nodegit - 在 Linux 中安装 nodegit 时出错