Github API:每天获取贡献数 [英] Github API: Get number of contributions on a day by day basis

查看:38
本文介绍了Github API:每天获取贡献数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Github API中获取每天的贡献数量.我正在制作一个网络应用程序,将github贡献的数量与我玩的Dota 2比赛的数量进行比较.

I want to GET from the Github API, the number of contributions per day. I'm making a webapp that compares the number of github contributions to the number of Dota 2 matches I play.

这张图片应该可以更清楚地解释事情.

This picture should explain things more clearly.

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

我在Github API和Internet上寻找了一个简单的解决方案,而我所看到的一些答案并不是我想要的.这个 Github API获得去年的提交活动 blurb是我最近的一个已经找到一种解决方案,但是使用它会涉及对我的帐户中的所有存储库进行API调用,并将数据连接到一个JSON中.如果没有解决方案,我想知道,所以我可以放弃运输.

I have scoured the Github API and the internet looking for a simple solution and some of the answers I've seen weren't what I was looking for. This Github API get last year of commit activity blurb is the closest I've gotten to finding a solution, but using it would involve making the API call for ALL repos in my account and concatenating the data into one JSON. If there are no solutions to this I would like to know it so I can abandon ship.

谢谢!

推荐答案

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

You can use the svg calendar data with the url :

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

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

You can set the to query param to your target day and then parse the svg result to get the last data in the output calendar.

对于Web集成部分,您可以使用 urlreq 之类的代理.一个例子:

For the web integration part, you can use a proxy like urlreq. An example :

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

这篇关于Github API:每天获取贡献数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆