Mercurial > eagle-eye
changeset 10:f590b5ea5e55
fixed bug of sheep.pl
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 08 Oct 2008 09:55:43 +0800 |
parents | ae412d1f7761 |
children | e21b8f303c6a |
files | Ikariam.pm scan.pl scores.pl sheep.pl |
diffstat | 4 files changed, 90 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/Ikariam.pm Wed Oct 08 04:30:32 2008 +0800 +++ b/Ikariam.pm Wed Oct 08 09:55:43 2008 +0800 @@ -185,6 +185,21 @@ or die "gunzip failed: $GunzipError\n"; my $html = HTML::TagParser->new($c); + + # find inactivity and vacation + my %status; + foreach my $class (qw/inactivity vacation/) + { + @elems = $html->getElementsByAttribute("class", $class); + foreach my $elem (@elems) { + if($elem->innerText() =~ /^(.*?) \((\w)\)/) { + $status{$1} = $2; + # printf("%s\n", $elem->innerText()); + } + } + } + + # find content my @elems = $html->getElementsByClassName( "cityinfo" ); my @cities; foreach my $elem (@elems) { @@ -203,6 +218,14 @@ $info{'user'} = $1; $info{'cityId'} = $2; } + + # update status; + if(defined($status{$info{'cityname'}})) { + $info{'status'} = $status{$info{'cityname'}}; + } else { + $info{'status'} = undef; + } + # print(Dumper(\%info)); push @cities, \%info; }
--- a/scan.pl Wed Oct 08 04:30:32 2008 +0800 +++ b/scan.pl Wed Oct 08 09:55:43 2008 +0800 @@ -6,16 +6,22 @@ my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); $i->login; - +my @islands; if($#ARGV == 1) { @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); +} elsif($#ARGV == 0) { + my $island = $ARGV[0]; + + my @cities = $i->viewIsland($island); + saveCities($island, @cities); + $i->logout; + exit; } elsif($#ARGV == -1) { @islands = $i->viewHomeMap(); } else { die("Usage: $0\nUsage: $0 x y\n"); } -my @islands; foreach my $island (@islands) { printf("checking island %d\n", $island->{id}); @@ -29,9 +35,16 @@ # scanning the island my @cities = $i->viewIsland($island->{id}); + saveCities($island->{id}, @cities); +} + +sub saveCities +{ + my ($island, @cities) = @_; + foreach my $city (@cities) { - $city->{island} = $island->{id}; + $city->{island} = $island; if(my $c = Ikariam::Cities->retrieve($city->{cityId})) { foreach my $i (keys(%$city)) @@ -49,5 +62,5 @@ printf("city %d %s saved\n", $city->{cityId}, $city->{cityname}); } } - +$i->logout; # $i->getCityInfo();
--- a/scores.pl Wed Oct 08 04:30:32 2008 +0800 +++ b/scores.pl Wed Oct 08 09:55:43 2008 +0800 @@ -37,6 +37,7 @@ $users = $i->viewScore($x, $ARGV[0], 0); saveUser($users); } + $i->logout; } elsif ($#ARGV == 1) { $i->login; @@ -70,6 +71,7 @@ saveUser($users); } } + $i->logout; } else { # my $users = $i->viewScore('army_score_main'); # saveUser($users);
--- a/sheep.pl Wed Oct 08 04:30:32 2008 +0800 +++ b/sheep.pl Wed Oct 08 09:55:43 2008 +0800 @@ -6,6 +6,18 @@ package main; Ikariam::User->has_many(cities => 'Ikariam::Cities'); +Ikariam::User->set_sql(inactivity => qq { + SELECT user.id + FROM user, cities, island + WHERE user.id == cities.user + AND cities.island == island.id + AND island.x <= ? + AND island.x >= ? + AND island.y <= ? + AND island.y >= ? + AND user.status = 'i' + } +); Ikariam::User->set_sql(sheeps => qq { SELECT user.id FROM user, cities, island @@ -16,7 +28,7 @@ AND island.y <= ? AND island.y >= ? AND user.score >= 500 - AND user.army_score_main <= 20 + AND user.army_score_main <= 25 } ); @@ -25,25 +37,43 @@ } my ($x, $y) = @ARGV; -my @sheeps = Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); -my $s; -foreach my $sheep (sort (@sheeps)) { - # avoid duplicate - next if($sheep->id == $s); $s = $sheep->id; +listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); +listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); + + +sub listSheeps +{ + my @sheeps = @_; - # 查聯盟數量 - next if(Ikariam::User->search(allyId => $sheep->allyId)->count() > 3); + my $s; + foreach my $sheep (sort (@sheeps)) { + # avoid duplicate + next if($sheep->id == $s); $s = $sheep->id; + + # 假期模式 + next if($sheep->status eq 'v'); - printf("%s (%s),%d,%d\n", $sheep->name, $sheep->ally, $sheep->score, $sheep->army_score_main); - # print Dumper($sheep->_data_hash); - foreach my $c ($sheep->cities) { - # print Dumper($c->_data_hash); - my $island = Ikariam::Island->retrieve($c->island); - printf("%s,%d,(%d,%d),http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, - $island->x, $island->y, - $island->id); + # 查聯盟數量 + my $members = 1; + unless ($sheep->status eq 'i') { + $members = Ikariam::User->search(allyId => $sheep->allyId)->count(); + next if($members > 3); + } + + # print Dumper($sheep->_data_hash); + foreach my $c ($sheep->cities) { + # print Dumper($c->_data_hash); + + print("!") if ($c->status eq 'i'); + + printf("%d,%d,%d,%s of %s (%d),", $sheep->trader_score_secondary, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members); + + my $island = Ikariam::Island->retrieve($c->island); + printf("%s,%d,[%d,%d],http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, + $island->x, $island->y, + $island->id); + } + printf("\n"); } - printf("\n"); } - # find_or_create