annotate scan.pl @ 79:9d92e8c12f58

rewrited the code in XPath.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 24 Oct 2008 21:46:33 +0800
parents 96ee35378696
children 0fa9cd836e1e
rev   line source
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
3 use Data::Dumper;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Ikariam;
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 package main;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
7 sub saveCities
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
8 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
9 my ($island, @cities) = @_;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10
48
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
11 if ($#cities == -1) {
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
12 warn ("empty cities list.\n");
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
13 return;
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
14 }
25
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
15
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
16 foreach my $city (@cities)
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
17 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
18 $city->{island} = $island;
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
19 $city->{'time'} = time;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
20 if(my $c = Ikariam::Cities->retrieve($city->{cityId}))
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
21 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
22 foreach my $i (keys(%$city)) {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
23 eval($c->$i($city->{$i}));
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
24 # printf("%s %s ", $i, $city->{$i});
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
25 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
26 # print ("\n");
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
27
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
28 $c->autoupdate(1);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
29 $c->update();
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
30 } else {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
31 Ikariam::Cities->insert($city);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
32 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
33
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
34 printf("city %s (%d) at island (%d) saved\n",
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
35 $city->{cityname},
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
36 $city->{cityId},
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
37 $island);
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
38
25
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
39 my $user = Ikariam::User->retrieve($city->{user});
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
40 if(!defined($user) || $user->time le (time - 60*60*1)) {
25
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
41 # Download user profile.
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
42 foreach my $x (qw/score army_score_main trader_score_secondary/)
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
43 {
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
44 my $users = $::i->viewScore($x, $city->{owner}, 0);
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
45 saveUser($users);
20
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
46 }
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
47 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
48 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
49 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
50
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
51 sub saveUser
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
52 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
53 my $users = shift;
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
54
20
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
55 foreach my $h_user (values(%{$users}))
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
56 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
57 # print(Dumper($user));
20
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
58 printf("Saving user %s\n", $h_user->{'name'});
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
59 $h_user->{'time'} = time;
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
60 my $user;
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
61 if($user = Ikariam::User->retrieve($h_user->{id}))
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
62 {
20
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
63 foreach my $i (keys(%$h_user)) {
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
64 # eval($c->$i($h_user->{$i}));
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
65 $user->set($i => $h_user->{$i});
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
66 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
67 } else {
20
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
68 $user = Ikariam::User->insert($h_user);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
69 }
20
5635e75c92d0 the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 18
diff changeset
70 $user->update();
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
71 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
72 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
73
41
5849b6fdc76c removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 36
diff changeset
74 our $i = new Ikariam($::server, $::user, $::pass);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
75
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
76 my @islands;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
77 if($#ARGV == 1) {
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
78 $i->login;
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
79 @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
80 } elsif($#ARGV == 0) {
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
81 $i->login;
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
82 my $island = $ARGV[0];
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
83
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
84 my @cities = $i->viewIsland($island);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
85 saveCities($island, @cities);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
86 $i->logout;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
87 return;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
88 } elsif($#ARGV == -1) {
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
89 $i->login;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
90 @islands = $i->viewHomeMap();
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
91 } else {
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
92 die("Usage: $0\nUsage: $0 x y\n");
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
93 }
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
94
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
95 foreach my $h_island (@islands)
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
96 {
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
97 printf("checking island %d\n", $h_island->{id});
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
98
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
99 my $island;
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
100 if($island = Ikariam::Island->retrieve($h_island->{id})) {
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
101 foreach my $i (keys(%$h_island)) {
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
102 $island->set($i => $h_island->{$i});
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
103 }
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
104 } else {
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
105 $island = Ikariam::Island->insert($h_island);
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
106 }
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
107
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
108 # scanning the island
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
109 if($island->time le (time - 60*60*6))
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
110 {
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
111 my @cities = $i->viewIsland($h_island->{id});
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
112 saveCities($h_island->{id}, @cities);
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
113
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
114 $island->set('time', time);
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
115 }
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
116 $island->update();
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
117
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
118 }
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
119 $i->logout;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
120 # $i->getCityInfo();