# HG changeset patch # User "Rex Tsai " # Date 1225421068 -28800 # Node ID 124fc7abda39a858378bba91a06c532ba82a59ce # Parent 3bbb1e559e21e6814a848a38b5d6838d860df5e7 scan all the islands nearby our own cities. diff -r 3bbb1e559e21 -r 124fc7abda39 scan.pl --- a/scan.pl Fri Oct 31 10:11:00 2008 +0800 +++ b/scan.pl Fri Oct 31 10:44:28 2008 +0800 @@ -4,6 +4,7 @@ use Ikariam; package main; + sub saveCities { my ($island, @cities) = @_; @@ -77,48 +78,55 @@ our $i = new Ikariam($::server, $::user, $::pass); -my @islands; if($#ARGV == 1) { $i->login; - @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); + my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); + saveIslands(@islands); + $i->logout; } elsif($#ARGV == 0) { $i->login; my $island = $ARGV[0]; - my @cities = $i->viewIsland($island); saveCities($island, @cities); $i->logout; - exit; } elsif($#ARGV == -1) { $i->login; - @islands = $i->viewHomeMap(); + my $cities = $i->check; + foreach my $cityId (keys(%$cities)) { + my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y}); + saveIslands(@islands); + } + $i->logout; } else { die("Usage: $0\nUsage: $0 x y\n"); } -foreach my $h_island (@islands) -{ - printf("checking island %d\n", $h_island->{id}); +sub saveIslands { + my @islands = shift; - my $island; - if($island = Ikariam::Island->retrieve($h_island->{id})) { - foreach my $i (keys(%$h_island)) { - $island->set($i => $h_island->{$i}); - } - } else { - $island = Ikariam::Island->insert($h_island); - } + foreach my $h_island (@islands) + { + printf("checking island %d\n", $h_island->{id}); - # scanning the island - if($island->time le (time - 60*60*6)) - { - my @cities = $i->viewIsland($h_island->{id}); - saveCities($h_island->{id}, @cities); + my $island; + if($island = Ikariam::Island->retrieve($h_island->{id})) { + foreach my $i (keys(%$h_island)) { + $island->set($i => $h_island->{$i}); + } + } else { + $island = Ikariam::Island->insert($h_island); + } - $island->set('time', time); - } - $island->update(); + # scanning the island + if($island->time le (time - 60*60*6)) + { + my @cities = $i->viewIsland($h_island->{id}); + saveCities($h_island->{id}, @cities); + $island->set('time', time); + } + $island->update(); + + } } -$i->logout; # $i->getCityInfo();