我意识到我可以点击https://api.github.com/users/:user_id/repos
获取我拥有或已经分叉的所有回购列表。但我想要做的是弄清楚我去年所做的所有项目(提交,拉取请求,问题等)。 events API让我获得了最近300个活动,但是我提供了超过过去12个月的批次。这可能吗?
答案 0 :(得分:5)
感谢来自a tweet的@caged,我写了this Perl script在my contributions中迭代了几个月:
use v5.12;
use warnings;
use utf8;
my $uname = 'theory';
my %projects;
for my $year (2012..2014) {
for my $month (1..12) {
last if $year == 2014 && $month > 1;
my $from = sprintf '%4d-%02d-01', $year, $month;
my $to = sprintf '%4d-%02d-01', $month == 12 ? ($year + 1, 1) : ($year, $month + 1);
my $res = `curl 'https://github.com/$uname?tab=contributions&from=$from&to=$to' | grep 'class="title"'`;
while ($res =~ /href="([^"?]+)/g) {
my (undef, $user, $repo) = split m{/} => $1;
$projects{"$user/$repo"}++;
}
}
}
say "$projects{$_}: $_" for sort keys %projects;
是的,HTML抓取是一种丑陋的行为,但却能满足我的需求。