Mercurial > eagle-eye
changeset 23:54ab0becd730
implemented a prototype for collecting account status.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 09 Oct 2008 11:33:47 +0800 |
parents | 552528bb4917 |
children | 93d4e6ffe330 |
files | Ikariam.pm ally.pl sheep.pl |
diffstat | 3 files changed, 72 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Ikariam.pm Wed Oct 08 19:27:54 2008 +0800 +++ b/Ikariam.pm Thu Oct 09 11:33:47 2008 +0800 @@ -235,6 +235,66 @@ return @cities; } +sub check +{ + my $self = shift; + + my $aaaa = $self->{'cities'}; + + # 運輸船 + # CargoShip + foreach my $i (keys(%{$self->{'cities'}})) + { + + # search for goods + my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ + action => 'header', + cityId => $i, + function => 'changeCurrentCity', + id => $i, + oldView => 'city', + ]); + my $c; + my $status = gunzip \$res->content => \$c + or die "gunzip failed: $GunzipError\n"; + + my $html = HTML::TagParser->new($c); + my @elems; + + foreach my $j (qw/value_wood value_wine value_marble value_crystal value_sulfur/) { + my ($elem) = $html->getElementsByAttribute("id", $j); + $self->{'cities'}->{$i}->{$j} = $elem->innerText(); + $self->{'cities'}->{$i}->{$j} =~ s/,//g; + } + + my %types; + $types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; + $types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; + + foreach my $x (qw/army fleet/) + { + $self->{'cities'}->{$i}->{$x} = {}; + # search army + $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $i)); + $status = gunzip \$res->content => \$c + or die "gunzip failed: $GunzipError\n"; + + $html = HTML::TagParser->new($c); + @elems = $html->getElementsByTagName('td'); + + foreach my $j (0..$#{$types{$x}}) { + next if($types{$x}[$j] eq 'undef'); + if($elems[$j]->innerText() == '-') { + $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = 0; + } else { + $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = $elems[$j]->innerText(); + } + } + } + } + print Dumper($self->{'cities'}); +} + sub logout { my $self = shift; @@ -256,6 +316,15 @@ if($c =~ /錯誤!/) { die ("password error\n"); + } else { + my $html = HTML::TagParser->new($c); + my @elems; + + @elems = $html->getElementsByAttribute("class", "avatarCities coords"); + foreach my $elem (@elems) { + # my cities + $self->{'cities'}->{$elem->getAttribute('value')} = {}; + } } }