comparison scan.pl @ 2:0fb73a7a0b94

ok, we done basic island scanning functions.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 07 Oct 2008 23:22:09 +0800
parents f9eac5385dc0
children dbb97c4265ba
comparison
equal deleted inserted replaced
1:f9eac5385dc0 2:0fb73a7a0b94
2 use strict; 2 use strict;
3 use Ikariam; 3 use Ikariam;
4 4
5 package main; 5 package main;
6 6
7 use Class::DBI::AutoLoader (
8 dsn => 'dbi:SQLite:dbname=ikariam.sqlite',
9 options => { RaiseError => 1 },
10 tables => ['cities', 'islands'],
11 use_base => 'Class::DBI::SQLite',
12 namespace => 'Ikariam',
13 );
14
15 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); 7 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
16 $i->login; 8 $i->login;
17 # my @islands = $i->viewHomeMap(); 9
18 # my @islands = $i->viewWorldMap(89, 60); 10 my @islands;
19 my @islands = $i->viewWorldMap(50, 34); 11 if($#ARGV >= 2) {
12 @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
13 } else {
14 @islands = $i->viewHomeMap();
15 }
16 # my @islands = $i->viewWorldMap(50, 34);
20 17
21 foreach my $island (@islands) 18 foreach my $island (@islands)
22 { 19 {
23 printf("checking island %d\n", $island->{id}); 20 printf("checking island %d\n", $island->{id});
24 if(my $c = Ikariam::Islands->retrieve($island->{id})) { 21 if(my $c = Ikariam::Islands->retrieve($island->{id})) {
32 # scanning the island 29 # scanning the island
33 my @cities = $i->viewIsland($island->{id}); 30 my @cities = $i->viewIsland($island->{id});
34 foreach my $city (@cities) 31 foreach my $city (@cities)
35 { 32 {
36 $city->{island} = $island->{id}; 33 $city->{island} = $island->{id};
37 printf("checking city %d\n", $city->{cityId});
38 if(my $c = Ikariam::Cities->retrieve($city->{cityId})) 34 if(my $c = Ikariam::Cities->retrieve($city->{cityId}))
39 { 35 {
40 foreach my $i (keys(%$city)) 36 #foreach my $i (keys(%$city))
41 { 37 #{
42 eval($c->$i($city->{$i})); 38 # eval($c->$i($city->{$i}));
43 printf("%s %s ", $i, $city->{$i}); 39 # printf("%s %s ", $i, $city->{$i});
44 } 40 #}
45 print ("\n"); 41 #print ("\n");
46 42
43 $c->autoupdate(1);
47 $c->update(); 44 $c->update();
48 } else { 45 } else {
49 Ikariam::Cities->insert($city); 46 Ikariam::Cities->insert($city);
50 } 47 }
48 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname});
51 } 49 }
52 } 50 }
53 51
54 52
55 # TODO 53 # TODO