changeset 140:124fc7abda39

scan all the islands nearby our own cities.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 10:44:28 +0800
parents 3bbb1e559e21
children 0da6658697df
files scan.pl
diffstat 1 files changed, 33 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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();