【问题标题】:Github API: Get number of contributions on a day by day basisGithub API:每天获取贡献数量
【发布时间】:2020-05-27 03:54:13
【问题描述】:
【问题讨论】:
标签:
github
get
github-api
【解决方案1】:
您可以使用带有 url 的 svg 日历数据:
https://github.com/users/USER/contributions?to=2016-12-25
您可以将 to 查询参数设置为您的目标日期,然后解析 svg 结果以获取输出日历中的最后一个数据。
对于网络集成部分,您可以使用urlreq 之类的代理。一个例子:
const user = 'bertrandmartel';
const day = "2016-12-25";
fetch('https://urlreq.appspot.com/req?method=GET&url=https%3A%2F%2Fgithub.com%2Fusers%2F' + user + '%2Fcontributions%3Fto%3D' + day)
.then(function(response) {
return response.text();
})
.then(function(text) {
xmlDoc = new DOMParser().parseFromString(text, 'text/xml');
var nodes = xmlDoc.getElementsByTagName('rect');
var dayContributions = nodes[nodes.length-1].getAttribute('data-count');
console.log('contributions count for ' + day + ' : ' + dayContributions);
})
.catch(function(error) {
console.log('Request failed', error)
});