comparison scan.pl @ 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 6043e9bfdeef
children 0da6658697df
comparison
equal deleted inserted replaced
139:3bbb1e559e21 140:124fc7abda39
2 use strict; 2 use strict;
3 use Data::Dumper; 3 use Data::Dumper;
4 use Ikariam; 4 use Ikariam;
5 5
6 package main; 6 package main;
7
7 sub saveCities 8 sub saveCities
8 { 9 {
9 my ($island, @cities) = @_; 10 my ($island, @cities) = @_;
10 11
11 if ($#cities == -1) { 12 if ($#cities == -1) {
75 } 76 }
76 } 77 }
77 78
78 our $i = new Ikariam($::server, $::user, $::pass); 79 our $i = new Ikariam($::server, $::user, $::pass);
79 80
80 my @islands;
81 if($#ARGV == 1) { 81 if($#ARGV == 1) {
82 $i->login; 82 $i->login;
83 @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); 83 my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
84 saveIslands(@islands);
85 $i->logout;
84 } elsif($#ARGV == 0) { 86 } elsif($#ARGV == 0) {
85 $i->login; 87 $i->login;
86 my $island = $ARGV[0]; 88 my $island = $ARGV[0];
87
88 my @cities = $i->viewIsland($island); 89 my @cities = $i->viewIsland($island);
89 saveCities($island, @cities); 90 saveCities($island, @cities);
90 $i->logout; 91 $i->logout;
91 exit;
92 } elsif($#ARGV == -1) { 92 } elsif($#ARGV == -1) {
93 $i->login; 93 $i->login;
94 @islands = $i->viewHomeMap(); 94 my $cities = $i->check;
95 foreach my $cityId (keys(%$cities)) {
96 my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
97 saveIslands(@islands);
98 }
99 $i->logout;
95 } else { 100 } else {
96 die("Usage: $0\nUsage: $0 x y\n"); 101 die("Usage: $0\nUsage: $0 x y\n");
97 } 102 }
98 103
99 foreach my $h_island (@islands) 104 sub saveIslands {
100 { 105 my @islands = shift;
101 printf("checking island %d\n", $h_island->{id});
102 106
103 my $island; 107 foreach my $h_island (@islands)
104 if($island = Ikariam::Island->retrieve($h_island->{id})) { 108 {
105 foreach my $i (keys(%$h_island)) { 109 printf("checking island %d\n", $h_island->{id});
106 $island->set($i => $h_island->{$i}); 110
111 my $island;
112 if($island = Ikariam::Island->retrieve($h_island->{id})) {
113 foreach my $i (keys(%$h_island)) {
114 $island->set($i => $h_island->{$i});
115 }
116 } else {
117 $island = Ikariam::Island->insert($h_island);
107 } 118 }
108 } else { 119
109 $island = Ikariam::Island->insert($h_island); 120 # scanning the island
121 if($island->time le (time - 60*60*6))
122 {
123 my @cities = $i->viewIsland($h_island->{id});
124 saveCities($h_island->{id}, @cities);
125
126 $island->set('time', time);
127 }
128 $island->update();
129
110 } 130 }
111
112 # scanning the island
113 if($island->time le (time - 60*60*6))
114 {
115 my @cities = $i->viewIsland($h_island->{id});
116 saveCities($h_island->{id}, @cities);
117
118 $island->set('time', time);
119 }
120 $island->update();
121
122 } 131 }
123 $i->logout;
124 # $i->getCityInfo(); 132 # $i->getCityInfo();