Mercurial > eagle-eye
changeset 150:fab1593cadf1
fixed the combat reading issue.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sat, 01 Nov 2008 03:52:09 +0800 |
parents | 97dfcc0d1e3f |
children | 7071116f6ae7 637314cc57ed |
files | Ikariam.pm agent.pl |
diffstat | 2 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Ikariam.pm Sat Nov 01 02:01:53 2008 +0800 +++ b/Ikariam.pm Sat Nov 01 03:52:09 2008 +0800 @@ -37,7 +37,6 @@ return $self; } -# parse($Content); sub parse { my ($self, $content) = @_; my $string; @@ -68,7 +67,10 @@ return undef unless defined($result); if ( $result->isa( 'XML::LibXML::NodeList' ) ) { - return () if($result->size() == 0); + if($result->size() == 0) { + return undef unless wantarray; + return (); + } foreach ( @$result ) { # $_ is XML::LibXML::Element, XML::LibXML::Node my $literal = $_->to_literal(); @@ -577,17 +579,21 @@ $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]'); $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]'); + # the combat we win! $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()'); my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href'); - # $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); - # my $href = $extractor->find('//td[@class="battle"]/a/@href'); + if(!defined($href)) { + # the combat we lost! + $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); + $href = $extractor->find('//td[@class="battle"]/a/@href'); + } if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) { $report{island} = $1; $report{city} = $2; } else { + warn($href); warn ("can not read combat reprot $combatId"); - warn ($href); return undef; } $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]');
--- a/agent.pl Sat Nov 01 02:01:53 2008 +0800 +++ b/agent.pl Sat Nov 01 03:52:09 2008 +0800 @@ -20,10 +20,6 @@ sub is_attacked { my ($self, $city) = @_; - if($self->{'ikariam'}->{'military'}->{attacks} > 0) { - # notify youself. - system('zenity --warning --title="Ikariam" --text="You are attacked"'); - } return ($self->{'ikariam'}->{'military'}->{attacks} > 0 ) ? 1 : 0; } @@ -292,7 +288,9 @@ # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose)); } # print(Dump($cities)) if(defined($verbose)); -DumpFile("dump.yaml", $cities); +DumpFile("cities-dump.yaml", $cities); +DumpFile("research-dump.yaml", $i->{'research'}); +DumpFile("military-dump.yaml", $i->{'military'}); $i->logout;