comparison scan.pl @ 252:d75f26fc1c69

fixed saving ally
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 17 Nov 2008 12:44:42 +0800
parents a654d43731f0
children 1e4922d9a671
comparison
equal deleted inserted replaced
251:5527133b7c7e 252:d75f26fc1c69
96 if(defined($ally)) { 96 if(defined($ally)) {
97 foreach (keys(%$h_ally)) { $ally->set($_ => $h_ally->{$_}); } 97 foreach (keys(%$h_ally)) { $ally->set($_ => $h_ally->{$_}); }
98 } else { 98 } else {
99 $ally = Ikariam::Ally->insert($h_ally); 99 $ally = Ikariam::Ally->insert($h_ally);
100 } 100 }
101 $ally->update();
101 } 102 }
102 } 103 }
103 104
104 sub saveIslands { 105 sub saveIslands {
105 my ($self, @islands) = @_; 106 my ($self, @islands) = @_;
120 $island = Ikariam::Island->insert($h_island); 121 $island = Ikariam::Island->insert($h_island);
121 } 122 }
122 123
123 # scanning the island 124 # scanning the island
124 # 10 minutes cache. 125 # 10 minutes cache.
125 if($island->time le (time - 60*10)) 126 if($island->time le (time - 60*10)) {
126 {
127 my $i = $self->{ikariam}->clone(); 127 my $i = $self->{ikariam}->clone();
128 my @cities = 128 my @cities =
129 $i->viewIsland($h_island->{id}); 129 $i->viewIsland($h_island->{id});
130 $self->saveCities($h_island->{id}, @cities); 130 $self->saveCities($h_island->{id}, @cities);
131 131
143 143
144 # local $SIG{ALRM} = sub { die "timeout\n" }; 144 # local $SIG{ALRM} = sub { die "timeout\n" };
145 # alarm 3; 145 # alarm 3;
146 our $i = new Ikariam($::server, $::user, $::pass); 146 our $i = new Ikariam($::server, $::user, $::pass);
147 147
148 $i->login;
148 if($#ARGV == 1) { 149 if($#ARGV == 1) {
149 $i->login;
150 my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); 150 my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
151 # my $s = new Ikariam::Scanner($i); 151 # my $s = new Ikariam::Scanner($i);
152 # $s->saveIslands(@islands); 152 # $s->saveIslands(@islands);
153 new Ikariam::Scanner($i)->saveIslands(@islands); 153 new Ikariam::Scanner($i)->saveIslands(@islands);
154 } elsif($#ARGV == 0) { 154 } elsif($#ARGV == 0) {
155 $i->login;
156 my $island = $ARGV[0]; 155 my $island = $ARGV[0];
157 my @cities = $i->viewIsland($island); 156 my @cities = $i->viewIsland($island);
158 new Ikariam::Scanner($i)->saveCities($island, @cities); 157 new Ikariam::Scanner($i)->saveCities($island, @cities);
159 } elsif($#ARGV == -1) { 158 } elsif($#ARGV == -1) {
160 $i->login;
161 my $cities = $i->check; 159 my $cities = $i->check;
162 # random 160 # random
163 foreach my $cityId (keys(%$cities)) { 161 foreach my $cityId (keys(%$cities)) {
164 my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y}); 162 my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
165 new Ikariam::Scanner($i)->saveIslands(@islands); 163 new Ikariam::Scanner($i)->saveIslands(@islands);