Github API:每天获得贡献数量

时间:2015-02-13 23:36:09

标签: github get github-api

我想从Github API获取GET每天的贡献数量。我正在制作一个webapp,将github贡献的数量与我玩的Dota 2匹配数量进行比较。

这张照片应该更清楚地解释一下。

http://i.stack.imgur.com/cZ1XK.png

我已经搜索了Github API和互联网寻找一个简单的解决方案,我所看到的一些答案并不是我想要的。这个Github API get last year of commit activity模糊是我找到解决方案的最接近的,但使用它会涉及在我的帐户中为所有repos进行API调用,并将数据连接成一个JSON。如果没有解决方案,我想知道它,所以我可以放弃发货。

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以将svg日历数据与url一起使用:

https://github.com/users/USER/contributions?to=2016-12-25

您可以将to查询参数设置为目标日期,然后解析svg结果以获取输出日历中的最后一个数据。

对于Web集成部分,您可以使用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)
  });

相关问题