Github API:按日获取贡献次数

4
我希望从Github API获取每天的贡献次数。我正在制作一个Web应用程序,比较Github贡献次数和我玩Dota 2比赛的次数。
这张图片应该更清楚地解释了问题。

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

我已经搜索了Github API和互联网,寻找一个简单的解决方案,但是我看到的一些答案并不是我想要的。这个Github API get last year of commit activity 是我找到的最接近解决方案的地方,但是使用它需要调用我的所有存储库的API,并将数据连接成一个JSON。如果没有解决方案,我想知道,这样我就可以放弃了。

谢谢!

1个回答

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)
  });


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接