其实在github上最新的承诺的项目,我有两个想法,让提交的总数,如何获得总数和利用API
一个想法是使用API,如:https://api.github.com/repos/mojombo/grit/commits
,这样可以得到所有提交,我们可以计算它得到总数和提交的历时日期。但主要的问题是提交次数太多,速度会变慢。
另一个想法是,因为我已经得到了使用API https://api.github.com/repos/mojombo/grit/contributors
的贡献者的统计数据,并且贡献者的总数与我在grit website中看到的数量相同,并且我从这个API调用中获得了贡献每个贡献者的总和,然后我总结所有贡献者的贡献,它应该与网站的价值相同,但不幸的是,它与513不同。代码如下,我可以知道为什么有差异吗?
import json, requests
all_contributors = list()
page_count = 1
total_contributions=0
while True:
contributors = requests.get("https://api.github.com/repos/mojombo/grit/contributors?page=%d"%page_count)
if contributors != None and contributors.status_code == 200 and len(contributors.json()) > 0:
all_contributors = all_contributors + contributors.json()
else:
break
page_count = page_count + 1
total_contributor=len(all_contributors)
for contr in all_contributors:
total_contributions=total_contributions+contr['contributions']
print("--------total contributor-----------%d" %total_contributor) //print 43
print("--------total commits-----------%d" %total_contributions) //print 497
感谢
我已经知道如何获取最新的提交:) – sweetyBaby