Skip to content

Instantly share code, notes, and snippets.

@hellojukay
Last active May 29, 2020 06:55
Show Gist options
  • Save hellojukay/d759e058976760eef9b736602c2f4beb to your computer and use it in GitHub Desktop.
Save hellojukay/d759e058976760eef9b736602c2f4beb to your computer and use it in GitHub Desktop.
fetch all github stars
#!/usr/bin/env perl
use LWP::UserAgent;
use HTTP::Request;
use JSON::Parse;
my $ua = LWP::UserAgent->new();
$ua->agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
# if you nedd proxy , don`t foreget it
# $ua->proxy(https => 'http://proxy.exmaple:3128');
# loop all stars util get empty response
# github api max page size is 100
for(my $page=1; $page < 10000; $page=$page+1) {
my $req = HTTP::Request->new(GET => "https://api.github.com/users/hellojukay/starred?per_page=100&page=$page" );
my $res = $ua->request($req);
my $json_text;
if ($res->is_success) {
$json_text = $res->content;
}else {
printf "request api.github.com fail ,http %d\n",$res->code;
exit 1;
}
my $array = JSON::Parse::parse_json($json_text);
if(@$array == 0){
exit 0;
}
foreach my $star (@$array) {
printf "%-*s %-s\n",70, $star->{html_url},$star->{description};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment