Mercurial > eagle-eye
annotate scan.pl @ 20:5635e75c92d0
the user profile is also cached for 1 hour.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 08 Oct 2008 16:56:22 +0800 |
parents | fd44e3a1f800 |
children | 552528bb4917 |
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 |
14
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
11 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
|
12 { |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
13 $city->{island} = $island; |
16
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
14
diff
changeset
|
14 $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
|
15 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
|
16 { |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
17 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
|
18 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
|
19 # 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
|
20 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
21 # print ("\n"); |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
22 |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
23 $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
|
24 $c->update(); |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
25 } else { |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
26 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
|
27 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
28 |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
29 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname}); |
20
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
30 if(my $user = Ikariam::User->retrieve($city->{user})) |
14
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
31 { |
20
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
32 if($user->time le (time - 60*60)) { |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
33 # Download user profile. |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
34 foreach my $x (qw/score army_score_main trader_score_secondary/) |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
35 { |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
36 my $users = $::i->viewScore($x, $city->{owner}, 0); |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
37 saveUser($users); |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
38 } |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
39 } |
14
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
40 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
41 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
42 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
43 |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
44 sub saveUser |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
45 { |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
46 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
|
47 |
20
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
48 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
|
49 { |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
50 # 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
|
51 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
|
52 $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
|
53 my $user; |
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
54 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
|
55 { |
20
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
56 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
|
57 # 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
|
58 $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
|
59 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
60 } else { |
20
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
61 $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
|
62 } |
20
5635e75c92d0
the user profile is also cached for 1 hour.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
63 $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
|
64 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
65 } |
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 our $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
68 |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
69 my @islands; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
70 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
|
71 $i->login; |
2
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
72 @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
|
73 } 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
|
74 $i->login; |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
75 my $island = $ARGV[0]; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
76 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
77 my @cities = $i->viewIsland($island); |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
78 saveCities($island, @cities); |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
79 $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
|
80 return; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
81 } 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
|
82 $i->login; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
83 @islands = $i->viewHomeMap(); |
2
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
84 } else { |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
85 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
|
86 } |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
87 |
18 | 88 foreach my $h_island (@islands) |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
89 { |
18 | 90 printf("checking island %d\n", $h_island->{id}); |
91 | |
92 my $island; | |
93 if($island = Ikariam::Island->retrieve($h_island->{id})) { | |
94 foreach my $i (keys(%$h_island)) { | |
95 $island->set($i => $h_island->{$i}); | |
96 } | |
97 } else { | |
98 $island = Ikariam::Island->insert($h_island); | |
99 } | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
100 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
101 # scanning the island |
18 | 102 if($island->time le (time - 60*60*12 )) |
16
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
14
diff
changeset
|
103 { |
18 | 104 my @cities = $i->viewIsland($h_island->{id}); |
105 saveCities($h_island->{id}, @cities); | |
106 } | |
16
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
14
diff
changeset
|
107 |
18 | 108 $island->set('time', time); |
109 $island->update(); | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
110 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
111 $i->logout; |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
112 # $i->getCityInfo(); |