git.shiar.nl
/
sc2-widget
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2e5c5f2
)
clan match from command line arguments
author
Mischa POSLAWSKY
<perl@shiar.org>
Tue, 30 Apr 2019 21:05:32 +0000
(23:05 +0200)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Tue, 30 Apr 2019 21:06:45 +0000
(23:06 +0200)
widget.pl
patch
|
blob
|
history
diff --git
a/widget.pl
b/widget.pl
index 8f118d51ff325dc377b5dabcba39b9a278a9eea0..6c02c0bd2cec780ece29040d4625665337db277e 100644
(file)
--- a/
widget.pl
+++ b/
widget.pl
@@
-8,8
+8,9
@@
use LWP::Authen::OAuth2;
use JSON qw( decode_json );
use List::Util qw( all );
use JSON qw( decode_json );
use List::Util qw( all );
-my $profileid = 2138280;
-my $clanmatch = 'Inno';
+my ($profileid, $clanmatch) = @ARGV; # clan host and name
+$profileid and $profileid =~ /\A\d+\z/
+ or die "Usage: $0 <profile id> [<clan name>]\n";
my $bliz = LWP::Authen::OAuth2->new(
client_id => '7f0f95ac9529474f854ee8d68a12c3e0',
my $bliz = LWP::Authen::OAuth2->new(
client_id => '7f0f95ac9529474f854ee8d68a12c3e0',
@@
-32,9
+33,12
@@
sub blizget {
my $ladders = blizget(legacy => profile => 2 => 1 => $profileid => 'ladders');
my ($ladder) = (
sort { $b->{characters}->@* <=> $a->{characters}->@* } # population desc
my $ladders = blizget(legacy => profile => 2 => 1 => $profileid => 'ladders');
my ($ladder) = (
sort { $b->{characters}->@* <=> $a->{characters}->@* } # population desc
- grep { all { fc $_->{clanName} eq fc $clanmatch } $_->{characters}->@* } # members
+ grep {
+ !$clanmatch or
+ all { fc $_->{clanName} eq fc $clanmatch } $_->{characters}->@*
+ } # members
$ladders->{currentSeason}->@*
$ladders->{currentSeason}->@*
-);
+)
or die "No matching groups found\n"
;
say JSON->new->canonical->pretty->encode({
league => ucfirst lc $ladder->{ladder}->[0]->{league},
say JSON->new->canonical->pretty->encode({
league => ucfirst lc $ladder->{ladder}->[0]->{league},