X-Git-Url: http://git.shiar.nl/sc2-widget/blobdiff_plain/8c443d69c70317d0a47cd980da764dedd3b98380..40b4c42a13072cbca943c75ab6af7c91cd3eb39a:/getsc2clan diff --git a/getsc2clan b/getsc2clan index 60cbc1a..6f486f9 100755 --- a/getsc2clan +++ b/getsc2clan @@ -6,11 +6,12 @@ use utf8; use Data::Dump qw( pp ); use LWP::Authen::OAuth2; use JSON qw( decode_json ); -use List::Util qw( all ); +use List::MoreUtils qw( all part nsort_by ); -my ($profileid, $clanmatch) = @ARGV; # clan host and name -$profileid and $profileid =~ /\A\d+\z/ - or die "Usage: $0 []\n"; +my ($profiles, $clanmatches) = part { /\D/ } @ARGV; # separate numbers +@{$profiles} + or die "Usage: $0 ... [...]\n"; +my ($clanmatch) = map { $_ && qr/\A(?:$_)\z/i } join '|', @{$clanmatches}; my %auth = do './.blizzard.passwd.pl' or die "no auth setup: $!\n"; my $bliz = LWP::Authen::OAuth2->new(%auth, @@ -27,21 +28,26 @@ sub blizget { return decode_json($json); } -# find largest group consisting entirely of clan members # prefer deprecated interface to prevent costly ladder search -my $ladderdata = blizget(legacy => profile => 2 => 1 => $profileid => 'ladders'); +my @ladderdata = map { + blizget(legacy => profile => 2 => 1 => $_ => 'ladders') +} @{$profiles}; +my %ladders = ( + map { $_->{ladder}->[0]->{ladderId} => $_ } # unique + grep { $_->{ladder}->[0]->{division} } + map { $_->{currentSeason}->@* } @ladderdata +); my @ladders = ( - sort { - $b->{ladder}->[0]->{wins}+$b->{ladder}->[0]->{losses} <=> - $a->{ladder}->[0]->{wins}+$a->{ladder}->[0]->{losses} + nsort_by { + -($_->{ladder}->[0]->{wins} + $_->{ladder}->[0]->{losses}) } # activity desc grep { !$clanmatch or - all { fc $_->{clanName} eq fc $clanmatch } $_->{characters}->@* + all { $_->{clanName} =~ $clanmatch } $_->{characters}->@* } # members - grep { $_->{ladder}->[0]->{division} } - $ladderdata->{currentSeason}->@* + values %ladders ) or die "No matching groups found\n"; + my (@members, %memberidx); $memberidx{ $_->{id} } //= push(@members, $_) && $#members for map { $_->{characters}->@* } @ladders;