comparison 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
comparison
equal deleted inserted replaced
9:ae412d1f7761 10:f590b5ea5e55
4 4
5 package main; 5 package main;
6 6
7 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); 7 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
8 $i->login; 8 $i->login;
9 9 my @islands;
10 if($#ARGV == 1) { 10 if($#ARGV == 1) {
11 @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); 11 @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
12 } elsif($#ARGV == 0) {
13 my $island = $ARGV[0];
14
15 my @cities = $i->viewIsland($island);
16 saveCities($island, @cities);
17 $i->logout;
18 exit;
12 } elsif($#ARGV == -1) { 19 } elsif($#ARGV == -1) {
13 @islands = $i->viewHomeMap(); 20 @islands = $i->viewHomeMap();
14 } else { 21 } else {
15 die("Usage: $0\nUsage: $0 x y\n"); 22 die("Usage: $0\nUsage: $0 x y\n");
16 } 23 }
17 24
18 my @islands;
19 foreach my $island (@islands) 25 foreach my $island (@islands)
20 { 26 {
21 printf("checking island %d\n", $island->{id}); 27 printf("checking island %d\n", $island->{id});
22 if(my $c = Ikariam::Island->retrieve($island->{id})) { 28 if(my $c = Ikariam::Island->retrieve($island->{id})) {
23 foreach my $i (keys(%$island)) { 29 foreach my $i (keys(%$island)) {
27 Ikariam::Island->insert($island); 33 Ikariam::Island->insert($island);
28 } 34 }
29 35
30 # scanning the island 36 # scanning the island
31 my @cities = $i->viewIsland($island->{id}); 37 my @cities = $i->viewIsland($island->{id});
38 saveCities($island->{id}, @cities);
39 }
40
41 sub saveCities
42 {
43 my ($island, @cities) = @_;
44
32 foreach my $city (@cities) 45 foreach my $city (@cities)
33 { 46 {
34 $city->{island} = $island->{id}; 47 $city->{island} = $island;
35 if(my $c = Ikariam::Cities->retrieve($city->{cityId})) 48 if(my $c = Ikariam::Cities->retrieve($city->{cityId}))
36 { 49 {
37 foreach my $i (keys(%$city)) 50 foreach my $i (keys(%$city))
38 { 51 {
39 eval($c->$i($city->{$i})); 52 eval($c->$i($city->{$i}));
47 Ikariam::Cities->insert($city); 60 Ikariam::Cities->insert($city);
48 } 61 }
49 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname}); 62 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname});
50 } 63 }
51 } 64 }
52 65 $i->logout;
53 # $i->getCityInfo(); 66 # $i->getCityInfo();