Skip to content

Instantly share code, notes, and snippets.

@tomill
Created October 3, 2012 14:44
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 tomill/3827298 to your computer and use it in GitHub Desktop.
Save tomill/3827298 to your computer and use it in GitHub Desktop.
Japanese Guild: PVP power?
[realm] [guild]
Blackrock Jagabata 1370410 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Proudmoore Harapeko Soul 789878 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ner'zhul MKD Gaming 759618 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Blackrock Ctrl Z 654721 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Blackrock Mikan 555394 |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Blackrock Tan Do Li Ga 522397 ||||||||||||||||||||||||||||||||||||||||||||||||||||
Ner'zhul DORIFU 486190 ||||||||||||||||||||||||||||||||||||||||||||||||
Proudmoore CAVAG 426243 ||||||||||||||||||||||||||||||||||||||||||
Proudmoore Heureka 391065 |||||||||||||||||||||||||||||||||||||||
Blackrock Wa 356934 |||||||||||||||||||||||||||||||||||
Proudmoore Mattari 345593 ||||||||||||||||||||||||||||||||||
Blackrock WASABI 298219 |||||||||||||||||||||||||||||
Maiev Yamato 291955 |||||||||||||||||||||||||||||
Blackrock Far East Endgame 246271 ||||||||||||||||||||||||
Blackrock Onion Warriors 196403 |||||||||||||||||||
Blackrock YMMO 166214 ||||||||||||||||
Proudmoore Ocha 133827 |||||||||||||
Moonrunner Kiraku 112846 |||||||||||
Blackrock Terrible Ferret 102143 ||||||||||
Proudmoore Millennium Falcon 98898 |||||||||
Blackrock Mockingbird 95140 |||||||||
Proudmoore Aigis 90887 |||||||||
Proudmoore Knights of Zodiac 86502 ||||||||
use strict;
use warnings;
use utf8;
use bignum;
use JSON;
use LWP::Simple;
use Try::Tiny;
use URI;
use Web::Scraper;
use App::Options(
option => {
debug => { type => 'boolean', default => 1 },
},
);
main();
exit;
sub main {
my $guilds = guilds(URI->new('http://wowactivity.herokuapp.com/'));
for my $guild (@$guilds) {
my $url = sprintf 'http://us.battle.net/wow/en/guild/%s/%s/roster?dir=a&view=guildActivity&minLvl=85&sort=weekly',
$guild->{realm},
$guild->{name};
debug($url);
my $members = active_members(URI->new($url));
my $hk_total = 0;
for my $member (@$members) {
my $url = sprintf 'http://us.battle.net/api/wow/character/%s/%s?locale=en_US&fields=pvp',
$guild->{realm},
$member->{name};
debug($url);
my $hk = hk_count(URI->new($url));
debug($hk);
$hk_total += $hk;
sleep 1; # :)
}
$guild->{hk_total} = $hk_total;
}
$guilds = [ sort { $b->{hk_total} <=> $a->{hk_total} } @$guilds ];
view($guilds);
}
sub view {
my $guilds = shift;
unshift @$guilds, {
realm => '[realm]',
name => '[guild]',
hk_total => '',
};
for my $guild (@$guilds) {
printf "%-15s\t%-20s\t%10s\t%s\n",
$guild->{realm},
$guild->{name},
$guild->{hk_total},
'|' x (($guild->{hk_total}-0) * 0.0001);
}
}
sub debug {
return unless $App::options{debug};
warn sprintf "[%s] %s\n", scalar localtime, "@_";
}
sub hk_count {
my $resource = shift;
my $content = LWP::Simple::get($resource);
my $stat = JSON::decode_json($content || '{}');
return $stat->{pvp}{totalHonorableKills} - 0;
}
sub guilds {
my $resource = shift;
my $parser = scraper {
process '#main table tr', 'guilds[]' => scraper {
process '//td[1]', 'realm' => 'TEXT';
process '//td[2]', 'name' => 'TEXT';
};
result 'guilds';
};
my $guilds = $parser->scrape($resource);
shift @$guilds; # pop header
return $guilds;
}
sub active_members { # yes, only page 1
my $resource = shift;
my $parser = scraper {
process '#roster tr', 'members[]' => scraper {
process 'td.name', 'name' => 'TEXT';
process 'td.weekly', 'weekly' => 'TEXT';
};
result 'members';
};
my $members = $parser->scrape($resource) || [];
use Data::Dump 'dump'; warn dump $members, $resource;
my $actives = [ grep { $_->{weekly} } @$members ];
}
@tomill
Copy link
Author

tomill commented Oct 4, 2012

now http://wowactivity.herokuapp.com/ include pvp power by @milai_wow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment