【问题标题】:Github API: Get number of contributions on a day by day basisGithub API:每天获取贡献数量
【发布时间】:2020-05-27 03:54:13
【问题描述】:

我想从 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 中。如果对此没有解决方案,我想知道它以便我可以弃船。

谢谢!

【问题讨论】:

    标签: 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)
      });

    【讨论】:

      猜你喜欢
      • 2017-04-03
      • 1970-01-01
      • 2012-11-06
      • 2018-09-24
      • 2014-01-09
      • 1970-01-01
      • 2017-11-18
      • 2017-12-14
      • 2013-01-08
      相关资源
      最近更新 更多