diff scan.pl @ 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 e4b3168d0319
children 8b7bc598ba06
line wrap: on
line diff
--- 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();