# HG changeset patch # User "Rex Tsai " # Date 1223405419 -28800 # Node ID 2040ccc956705cced5577bff8d33aa194f7637a4 # Parent 2975a94aa7a2da694c5fbefb908549438d62b5bf implemented scores collection. diff -r 2975a94aa7a2 -r 2040ccc95670 Ikariam.pm --- a/Ikariam.pm Wed Oct 08 01:52:18 2008 +0800 +++ b/Ikariam.pm Wed Oct 08 02:50:19 2008 +0800 @@ -3,7 +3,7 @@ use Class::DBI::AutoLoader ( dsn => 'dbi:SQLite:dbname=ikariam.sqlite', options => { RaiseError => 1 }, - tables => ['cities', 'islands', 'users'], + tables => ['cities', 'island', 'users'], use_base => 'Class::DBI::SQLite', namespace => 'Ikariam', ); @@ -12,7 +12,8 @@ use Data::Dumper; use LWP; -# use LWP::Debug qw(+ -conns); +# use LWP::Debug qw(+ -conns -trace -debug); +use LWP::Debug qw(+trace); use HTTP::Cookies; use WWW::Mechanize; use HTML::TagParser; @@ -43,7 +44,7 @@ my $user = shift || ''; my $offset = shift || 0; - my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ + my $res = $self->{mech}->post(sprintf("http://%s/index.php", $self->{server}), [ highscoreType => $type, offset => $offset, searchUser => $user, diff -r 2975a94aa7a2 -r 2040ccc95670 scan.pl --- a/scan.pl Wed Oct 08 01:52:18 2008 +0800 +++ b/scan.pl Wed Oct 08 02:50:19 2008 +0800 @@ -17,12 +17,12 @@ foreach my $island (@islands) { printf("checking island %d\n", $island->{id}); - if(my $c = Ikariam::Islands->retrieve($island->{id})) { + if(my $c = Ikariam::Island->retrieve($island->{id})) { foreach my $i (keys(%$island)) { eval($c->$i($island->{$i})); } } else { - Ikariam::Islands->insert($island); + Ikariam::Island->insert($island); } # scanning the island diff -r 2975a94aa7a2 -r 2040ccc95670 scores.pl --- a/scores.pl Wed Oct 08 01:52:18 2008 +0800 +++ b/scores.pl Wed Oct 08 02:50:19 2008 +0800 @@ -10,6 +10,7 @@ my $users = shift; foreach my $user (values(%{$users})) { + printf("Saving %s\n", $user->{'name'}); if(my $c = Ikariam::Users->retrieve($user->{id})) { foreach my $i (keys(%$user)) { @@ -24,7 +25,8 @@ } my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); -# $i->login; +$i->login; + if($#ARGV == 0) { my $users; foreach my $x (qw/score army_score_main trader_score_secondary/) @@ -32,10 +34,42 @@ $users = $i->viewScore($x, $ARGV[0], 0); saveUser($users); } +} elsif ($#ARGV == 1) { + # search the islands and cities nearby + my ($x, $y) = @ARGV; + my $offset = 5; + + Ikariam::Island->has_many(cities => 'Ikariam::Cities'); + + my @islands = Ikariam::Island->retrieve_from_sql( + "x >= " . ($x - $offset) . " AND " . " x <= " . ($x + $offset) . + " AND " . + "y >= " . ($y - $offset) . " AND " . " y <= " . ($y + $offset) + ); + + my %owners; + foreach my $island (@islands) + { + my @cities = $island->cities; + foreach my $city (@cities) + { + $owners{$city->owner} += 1; + } + } + + + foreach my $o (keys(%owners)) + { + foreach my $x (qw/score army_score_main trader_score_secondary/) + { + my $users = $i->viewScore($x, $o, 0); + saveUser($users); + } + } } else { - my $users = $i->viewScore('army_score_main'); - saveUser($users); - # die("Usage: $0 nickname\n"); + # my $users = $i->viewScore('army_score_main'); + # saveUser($users); + die("Usage: $0 nickname\n"); } # highscoreType