Skip to content

Instantly share code, notes, and snippets.

@bessarabov
Created April 16, 2021 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bessarabov/b64c8de53a005656aef7626f7a28e346 to your computer and use it in GitHub Desktop.
Save bessarabov/b64c8de53a005656aef7626f7a28e346 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
=encoding UTF-8
=cut
=head1 DESCRIPTION
=cut
# common modules
use strict;
use warnings FATAL => 'all';
use feature 'say';
use utf8;
use open qw(:std :utf8);
use Carp;
use HTTP::Tiny;
use JSON::PP;
use Data::Dumper;
use Path::Tiny;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Utils;
sub get_repos {
my ($page) = @_;
my $url = "https://api.github.com/search/repositories?q=home%20assistant%20custom%20lovelace%20card%20in:readme%20archived:false&sort=stars&page=$page&per_page=100";
my $response = HTTP::Tiny->new()->request(
'GET',
$url,
{
headers => {
'Authorization' => 'token ' . $ENV{'TOKEN'},
},
}
);
my $data;
if ($response->{status} eq '200') {
$data = decode_json $response->{content};
} else {
warn Dumper $response;
die;
}
return @{$data->{items}};
}
sub get_skip {
my @lines = path('skip_github_repos')->lines({ chomp => 1});
my %h;
foreach my $line (@lines) {
$line =~ /^(\S+)/;
$h{$1} = 1;
}
return %h;
}
sub get_known_gihhub_urls {
my @cards = get_cards('/Users/bessarabov/Dropbox/git/home-assistant-cards/data/');
my %h;
foreach my $card (@cards) {
$h{$card->{raw}->{site}} = 1;
}
return %h;
}
# main
sub main {
my %skip = get_skip();
my %known_gihhub_urls = get_known_gihhub_urls();
my $page = 1;
while (my @repos = get_repos($page)) {
foreach my $repo (@repos) {
my $url = $repo->{html_url};
next if $skip{$url};
next if $known_gihhub_urls{$url};
say $repo->{html_url};
}
$page++;
}
say '#END';
}
main();
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment