【发布时间】:2019-05-03 00:26:45
【问题描述】:
我正在尝试使用 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 个存储库中获得相同的结果? 我感谢所有有价值的信息。
【问题讨论】:
-
纯代码编写请求在 Stack Overflow 上是题外话——我们希望这里的问题与特定编程问题有关——但我们很乐意帮助您自己编写!告诉我们what you've tried,以及您遇到的问题。这也将有助于我们更好地回答您的问题。
-
谢谢肖恩。我会尽快更新我的问题。