获取所有公共用户贡献即“日历数据” (github API v3) [英] Get all public User contributions aka "calendar data" (github api v3)

查看:169
本文介绍了获取所有公共用户贡献即“日历数据” (github API v3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了很多线程 - 甚至有些项目使用api的github api嵌入贡献日历 - 但这些方法或线程都没有真正回答这个问题。



api文档描述收集Repo Contrib数据,所以我一味尝试用教育性的猜测捅了一口气,结果无济于事。有没有人可能知道事实上这个数据是否有可行的终点?我是否真的需要自己计算这些信息,或者做一些肮脏的HTML刮胡话?这似乎愚蠢的...任何人?



更新:
这是一个解决方案使用cheerio和正则表达式为任何人寻找一个快速的网页抓取解决方案

  const axios = require('axios')
const cheerio = require('cheerio')
const url ='https ://github.com/archae0pteryx'

function getCommits(url){
return new Promise((resolve,reject)=> {
axios.get(url) .then(res => {
const load = cheerio.load(res.data)
const parsed = load('div.js-contribution-graph> h2')。text()
const reg = / \ d + / g
const x = parsed.match(reg)
resolve(x)
})。catch(err => reject(err) )
))
}


getCommits(url)
.then(x => console.log(x))
.catch(err => console.error(err))


解决方案

您可以使用 xmlstartlet /github.com/users/archae0pteryx/contributionsrel =nofollow noreferrer> https://github.com/users/archae0pteryx/contributions 。



比抓取Github网站更好,但仍然无法使用官方API:

  curl -shttps:// github。 com / users / archae0pteryx / contributions| \ 
xmlstarlet sel -t -vsum(/ svg / g / g / rect / @ data-count)


I have found many threads - even a couple projects which embed the contribution calendar using api's other than the github api - yet none of these methods or threads actually answer the question. One comes close but it's a no go.

I am simply trying to access the total number of contributions for a user as shown in your calendar on the github profile page as shown below...

The api docs describe collecting Repo Contrib data so i've tried blindly poking at the api with educated guesses to no avail. Does anyone per-chance know if there in fact is a viable endpoint for this data? Do I really need to calculate this info myself or do some dirty html scraping nonsense? This seems dumb... Anyone?

UPDATE: Here's a solution using cheerio and regex for anyone looking for a quick web scraping solution

const axios = require('axios')
const cheerio = require('cheerio')
const url = 'https://github.com/archae0pteryx'

function getCommits(url) {
    return new Promise((resolve, reject) => {
        axios.get(url).then(res => {
            const load = cheerio.load(res.data)
            const parsed = load('div.js-contribution-graph > h2').text()
            const reg = /\d+/g
            const x = parsed.match(reg)
            resolve(x)
        }).catch(err => reject(err))
    })
}


getCommits(url)
    .then(x => console.log(x))
    .catch(err => console.error(err))

解决方案

You can use xmlstartlet to parse the xml file you get from your calendar svg : https://github.com/users/archae0pteryx/contributions.

It's better than scraping Github website but still fail to use the official API :

curl -s "https://github.com/users/archae0pteryx/contributions" | \
     xmlstarlet sel -t -v "sum(/svg/g/g/rect/@data-count)"

这篇关于获取所有公共用户贡献即“日历数据” (github API v3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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