Mercurial > eagle-eye
annotate Ikariam.pm @ 41:5849b6fdc76c
removed my password from scripts.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 17 Oct 2008 01:27:10 +0800 |
parents | 7d1e353520ca |
children | 96ee35378696 |
rev | line source |
---|---|
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/env perl |
41
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
37
diff
changeset
|
2 BEGIN { |
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
37
diff
changeset
|
3 my $HOME = (getpwuid($<))[7] || $ENV{HOME} || $ENV{LOGDIR} || "."; |
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
37
diff
changeset
|
4 require "$HOME/.eagleeye.pm"; |
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
37
diff
changeset
|
5 } |
2
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
6 |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
7 use Class::DBI::AutoLoader ( |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
8 dsn => 'dbi:SQLite:dbname=ikariam.sqlite', |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
9 options => { RaiseError => 1 }, |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
10 tables => ['cities', 'island', 'user'], |
2
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
11 use_base => 'Class::DBI::SQLite', |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
12 namespace => 'Ikariam', |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
13 ); |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
14 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
15 package Ikariam; |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
16 use strict; |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 use Data::Dumper; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 use LWP; |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
6
diff
changeset
|
19 # use LWP::Debug qw(+ -conns -trace -debug); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
6
diff
changeset
|
20 use LWP::Debug qw(+trace); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
21 use HTTP::Cookies; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
22 use WWW::Mechanize; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
23 use HTML::TagParser; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
24 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
25 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 sub new |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
28 my ($class, $server, $user, $pass) = @_; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
29 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
30 my $self = |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 { |
16
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
32 mech => WWW::Mechanize->new( |
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
33 agent => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092816 Iceweasel/3.0.1 (Debian-3.0.1-1)", |
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
34 timeout => 10, |
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
35 ), |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 server => $server, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
37 user => $user, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
38 pass => $pass, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
39 }; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
40 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
41 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
44 return bless $self, $class; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
45 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
46 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
47 sub viewScore |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
48 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
49 my $self = shift; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
50 my $type = shift || 'score'; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
51 my $user = shift || ''; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
52 my $offset = shift || 0; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
53 |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
6
diff
changeset
|
54 my $res = $self->{mech}->post(sprintf("http://%s/index.php", $self->{server}), [ |
6 | 55 highscoreType => $type, |
56 offset => $offset, | |
57 searchUser => $user, | |
58 view => 'highscore' | |
59 ]); | |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
60 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
61 my $c; |
6 | 62 my $status = gunzip \$res->content => \$c |
63 or die "gunzip failed: $GunzipError\n"; | |
64 | |
37
7d1e353520ca
just return empty users list, when the score link table is missed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
34
diff
changeset
|
65 my %users; |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
66 my $html = HTML::TagParser->new($c); |
37
7d1e353520ca
just return empty users list, when the score link table is missed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
34
diff
changeset
|
67 my ($table) = $html->getElementsByAttribute("class", "table01"); |
7d1e353520ca
just return empty users list, when the score link table is missed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
34
diff
changeset
|
68 return %users if(!defined($table)); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
69 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
70 my @elems = getElementsByTagName($table, "tr"); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
71 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
72 foreach my $elem (@elems) { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
73 my $e; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
74 my %user; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
75 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
76 $e = getElementsByAttribute($elem, "class", "action"); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
77 $e = getElementsByTagName($e, "a"); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
78 |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
79 if(defined ($e) && $e->getAttribute('href') =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
80 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
81 $user{'id'} = $1; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
82 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
83 $e = getElementsByAttribute($elem, "class", "name"); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
84 $user{'name'} = $e->innerText(); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
85 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
86 $e = getElementsByAttribute($elem, "class", "allytag"); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
87 $user{'ally'} = $e->innerText(); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
88 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
89 $e = getElementsByTagName($e, "a"); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
90 if($e->getAttribute('href') =~ /\?view=allyPage&allyId=(\d+)/) |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
91 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
92 $user{'allyId'} = $1; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
93 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
94 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
95 $e = getElementsByAttribute($elem, "class", "score"); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
96 $user{$type} = $e->innerText(); |
19 | 97 $user{$type} =~ s/,//g; |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
98 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
99 $users{$user{'id'}} = \%user; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
100 } else { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
101 next; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
102 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
103 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
104 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
105 return \%users; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
106 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
107 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
108 sub viewWorldMap |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
109 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
110 my $self = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
111 my $x = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
112 my $y = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
113 |
1 | 114 if(!defined($x) && !defined($y)) |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
115 { |
1 | 116 die('location required'); |
117 } | |
118 | |
119 my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
120 xajax => 'getMapData', |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
121 'xajaxargs[]' => $x, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
122 'xajaxargs[]' => $y, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
123 xajaxr => time, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
124 ]); |
1 | 125 |
126 my $c; | |
127 my $status = gunzip \$res->content => \$c | |
128 or die "gunzip failed: $GunzipError\n"; | |
129 | |
130 my @islands; | |
131 # parsing xjxobj | |
132 while($c =~ /<cmd n="jc" t="addToMap"><xjxobj><e><k>0<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>1<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>2<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>3<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>4<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>5<\/k><v><!\[CDATA\[(\w+)\]\]><\/v><\/e><e><k>6<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>7<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><\/xjxobj><\/cmd>/g) | |
133 { | |
134 my %island; | |
135 $island{id} = $3; | |
136 $island{x} = $1; | |
137 $island{y} = $2; | |
138 $island{name} = $6; | |
139 $island{tradegood} = $4; | |
140 $island{wonder} = $5; | |
141 # $7 ? | |
142 $island{people} = $8; | |
143 push @islands, \%island; | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
144 } |
1 | 145 return @islands; |
146 } | |
147 | |
3 | 148 sub viewHomeMap |
1 | 149 { |
150 my $self = shift; | |
151 | |
152 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server})); | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
153 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
154 my $c; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
155 my $status = gunzip \$res->content => \$c |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
156 or die "gunzip failed: $GunzipError\n"; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
157 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
158 # m[50][36]=new Array(564,1,5,'Risietia', '5', 13); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
159 # x = 43-57 = 6 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
160 # y = 27-41 = 6 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
161 my @islands; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
162 while($c =~ /m\[(\d+)\]\[(\d+)\]=new Array\((\d+),(\d+),(\d+),'(\w+)', '(\d+)', (\d+)\);/g) |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
163 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
164 my %island; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
165 $island{id} = $3; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
166 $island{x} = $1; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
167 $island{y} = $2; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
168 $island{name} = $6; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
169 $island{tradegood} = $4; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
170 $island{wonder} = $5; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
171 # $7 ? |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
172 $island{people} = $8; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
173 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
174 #foreach my $i (sort(keys(%island))) |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
175 #{ |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
176 # printf ("%s %s\n", $i, $island{$i}); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
177 #} |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
178 #print("\n"); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
179 push @islands, \%island; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
180 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
181 return @islands; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
182 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
183 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
184 sub viewIsland |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
185 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
186 my $self = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
187 my $island = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
188 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
189 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=island&id=%s", $self->{server}, $island)); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
190 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
191 my $c; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
192 my $status = gunzip \$res->content => \$c |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
193 or die "gunzip failed: $GunzipError\n"; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
194 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
195 my $html = HTML::TagParser->new($c); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
196 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
197 # find inactivity and vacation |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
198 my %status; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
199 foreach my $class (qw/inactivity vacation/) |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
200 { |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
201 my @elems = $html->getElementsByAttribute("class", $class); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
202 foreach my $elem (@elems) { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
203 if($elem->innerText() =~ /^(.*?) \((\w)\)/) { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
204 $status{$1} = $2; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
205 # printf("%s\n", $elem->innerText()); |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
206 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
207 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
208 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
209 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
210 # find content |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
211 my @elems = $html->getElementsByClassName( "cityinfo" ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
212 my @cities; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
213 foreach my $elem (@elems) { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
214 my %info; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
215 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
216 my @e = getElementsByTagName($elem, "li"); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
217 $info{'cityname'} = substr($e[0]->innerText(), 8); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
218 $info{'citylevel'} = substr($e[1]->innerText(), 14); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
219 $info{'owner'} = substr($e[2]->innerText(), 8); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
220 $info{'ally'} = substr($e[3]->innerText(), 8); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
221 delete($info{'ally'}) if($info{'ally'} eq '-'); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
222 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
223 @e = getElementsByAttribute($elem, "class", "messageSend"); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
224 if ( $e[0]->getAttribute("href") =~ /with=(\d+)&destinationCityId=(\d+)/) |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
225 { |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
226 $info{'user'} = $1; |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
227 $info{'cityId'} = $2; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
228 } |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
229 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
230 # update status; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
231 if(defined($status{$info{'cityname'}})) { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
232 $info{'status'} = $status{$info{'cityname'}}; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
233 } else { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
234 $info{'status'} = undef; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
235 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
236 # print(Dumper(\%info)); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
237 push @cities, \%info; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
238 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
239 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
240 return @cities; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
241 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
242 |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
243 sub check |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
244 { |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
245 my $self = shift; |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
246 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
247 # looking for cities |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
248 foreach my $cityId (keys(%{$self->{'cities'}})) |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
249 { |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
250 # search for goods |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
251 my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
252 action => 'header', |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
253 cityId => $cityId, |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
254 function => 'changeCurrentCity', |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
255 id => $cityId, |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
256 oldView => 'city', |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
257 ]); |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
258 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
259 my $content; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
260 gunzip \$res->content => \$content |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
261 or die "gunzip failed: $GunzipError\n"; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
262 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
263 my $html = HTML::TagParser->new($content); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
264 my @elems; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
265 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
266 my ($elem) = $html->getElementsByAttribute("id", "value_gold"); |
34
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
267 $self->{'cities'}->{$cityId}->{resources}->{gold} = $elem->innerText(); |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
268 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g; |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
269 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
270 my ($elem) = $html->getElementsByAttribute("class", "city"); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
271 $self->{'cities'}->{$cityId}->{name} = $elem->innerText(); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
272 |
30
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
273 my ($elem) = $html->getElementsByAttribute("class", 'constructionSite'); |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
274 $self->{'cities'}->{$cityId}->{construction} = 0; |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
275 $self->{'cities'}->{$cityId}->{construction} = 1 if(defined($elem)); |
de5de6d472f9
added space checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
29
diff
changeset
|
276 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
277 # check goods |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
278 foreach my $good (qw/wood wine marble crystal sulfur/) { |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
279 my ($elem) = $html->getElementsByAttribute("id", "value_" . $good); |
34
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
280 $self->{'cities'}->{$cityId}->{resources}->{$good} = $elem->innerText(); |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
281 $self->{'cities'}->{$cityId}->{resources}->{$good} =~ s/,//g; |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
282 } |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
283 |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
284 # search locations |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
285 foreach my $i (0..14) { |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
286 my ($elem) = $html->getElementsByAttribute("id", "position" . $i); |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
287 my $building = $elem->getAttribute('class'); |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
288 if ($building ne "buildingGround land") { |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
289 $self->{'cities'}->{$cityId}->{locations}[$i] = $building; |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
290 my $span = getElementsByAttribute($elem, "class", "textLabel"); |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
291 my (undef, undef, $level) = split(/ /, $span->innerText()); |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
292 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
293 } |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
294 } |
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
295 |
34
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
296 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server}, $cityId)); |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
297 gunzip \$res->content => \$content |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
298 or die "gunzip failed: $GunzipError\n"; |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
299 |
34
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
300 $self->{'cities'}->{$cityId}->{force}->{attacks} = $1 if($content =~ /敵人攻擊: (\d+)/); |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
301 $self->{'cities'}->{$cityId}->{force}->{wars} = $1 if($content =~ /我方軍隊行程: (\d+)/); |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
302 # if($content =~ /更新戰鬥報告: (\d+)/); |
91e387b51aa0
added more rules checking
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
30
diff
changeset
|
303 # if($content =~ /新的戰鬥報告: (\d+)/); |
29
dbec53e754e3
added rule_building
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
28
diff
changeset
|
304 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
305 # check townHall |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
306 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=townHall&id=%d', $self->{server}, $cityId)); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
307 gunzip \$res->content => \$content |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
308 or die "gunzip failed: $GunzipError\n"; |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
309 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
310 # check happiness |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
311 # Happiness = Basic bonuses (196 + Capital Bonus + Holiday Bonus(25)) + |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
312 # Wine (Tavern Base(12*level) + |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
313 # Tavern Bonus(80*step)) + |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
314 # Culture (Museum Base(20*level) + |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
315 # Cultural Goods Bonus(50*Cultural Goods)) - |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
316 # Population (population) - |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
317 # Corruption (Corruption rate * population) |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
318 # |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
319 # Growth Rate = Happiness * 0.02 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
320 $html = HTML::TagParser->new($content); |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
321 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
322 my @happiness = ("ecstatic", "happy", "neutral", "sad", "outraged"); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
323 foreach my $j (0..$#happiness) { |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
324 my ($elem) = $html->getElementsByAttribute("class", sprintf("happiness happiness_%s", $happiness[$j])); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
325 if(defined($elem)) { |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
326 $self->{'cities'}->{$cityId}->{happiness} = $j; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
327 $self->{'cities'}->{$cityId}->{happiness_text} = $happiness[$j]; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
328 } |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
329 } |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
330 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
331 # Space, 房屋數 |
28
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
332 $self->{'cities'}->{$cityId}->{"space"} = {}; |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
333 foreach my $j (qw/occupied total/) { |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
334 my ($elem) = $html->getElementsByAttribute("class", sprintf("value %s", $j)); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
335 if(defined($elem)) { |
28
99723b8f348b
added rule_corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
27
diff
changeset
|
336 $self->{'cities'}->{$cityId}->{"space"}->{$j} = $elem->innerText(); |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
337 } |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
338 } |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
339 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
340 # Actions |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
341 # <span id="value_maxActionPoints">1</span> |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
342 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
343 # <li class="incomegold incomegold_negative"> |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
344 # <li class="incomegold incomegold_positive"> |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
345 # <span class="value">-178</span> |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
346 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
347 my ($elem) = $html->getElementsByAttribute("title", "目前腐敗程度"); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
348 if(defined($elem)) { |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
349 $self->{'cities'}->{$cityId}->{corruption} = $elem->innerText(); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
350 $self->{'cities'}->{$cityId}->{corruption} =~ s/%//g; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
351 } |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
352 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
353 # count |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
354 my @citizens_type = qw/citizens woodworkers specialworkers scientists/; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
355 @elems = $html->getElementsByAttribute('class', 'count'); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
356 $self->{'cities'}->{$cityId}->{'citizens'} = {}; |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
357 $self->{'cities'}->{$cityId}->{'citizens'}->{total} = 0; |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
358 |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
359 foreach my $i (0..$#citizens_type) |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
360 { |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
361 $self->{'cities'}->{$cityId}->{'citizens'}->{$citizens_type[$i]} = $elems[$i]->innerText(); |
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
362 $self->{'cities'}->{$cityId}->{'citizens'}->{total} += $elems[$i]->innerText();; |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
363 } |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
364 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
365 # production |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
366 # skin/resources/icon_gold.gif |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
367 # skin/resources/icon_wood.gif |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
368 # skin/resources/icon_sulfur.gif (?) |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
369 # skin/resources/icon_research.gif |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
370 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
371 |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
372 # check armies |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
373 my %force_types; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
374 $force_types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
375 $force_types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
376 foreach my $x (qw/army fleet/) |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
377 { |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
378 $self->{'cities'}->{$cityId}->{$x} = {}; |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
379 # search army |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
380 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $cityId)); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
381 gunzip \$res->content => \$content |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
382 or die "gunzip failed: $GunzipError\n"; |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
383 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
384 $html = HTML::TagParser->new($content); |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
385 @elems = $html->getElementsByTagName('td'); |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
386 foreach my $j (0..$#{$force_types{$x}}) { |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
387 next if($force_types{$x}[$j] eq 'undef'); |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
388 if($elems[$j]->innerText() == '-') { |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
389 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = 0; |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
390 } else { |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
391 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = $elems[$j]->innerText(); |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
392 } |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
393 } |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
394 } |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
395 } |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
396 # print Dumper($self->{'cities'}); |
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
397 return $self->{'cities'}; |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
398 } |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
399 |
9
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
400 sub logout |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
401 { |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
402 my $self = shift; |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
403 $self->{mech}->get(sprintf('http://%s/index.php?action=loginAvatar&function=logout', $self->{server})); |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
404 } |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
405 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
406 sub login |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
407 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
408 my $self = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
409 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
410 my $res = $self->{mech}->post(sprintf("http://%s/index.php?action=loginAvatar&function=login", $self->{server}), [ |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
411 name => $self->{user}, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
412 password => $self->{pass}, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
413 ]); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
414 my $c; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
415 my $status = gunzip \$res->content => \$c |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
416 or die "gunzip failed: $GunzipError\n"; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
417 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
418 if($c =~ /錯誤!/) |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
419 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
420 die ("password error\n"); |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
421 } else { |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
422 my $html = HTML::TagParser->new($c); |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
423 my @elems; |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
424 |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
425 @elems = $html->getElementsByAttribute("class", "avatarCities coords"); |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
426 foreach my $elem (@elems) { |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
427 # my cities |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
428 $self->{'cities'}->{$elem->getAttribute('value')} = {}; |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
429 } |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
430 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
431 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
432 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
433 sub getElementsByTagName { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
434 my $element = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
435 my $tagname = lc(shift); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
436 my ( $flat, $cur ) = @$element; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
437 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
438 my $out = []; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
439 for( ; $cur <= $#$flat ; $cur++ ) { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
440 next if ( $flat->[$cur]->[001] ne $tagname ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
441 next if $flat->[$cur]->[000]; # close |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
442 my $elem = HTML::TagParser::Element->new( $flat, $cur ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
443 return $elem unless wantarray; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
444 push( @$out, $elem ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
445 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
446 return unless wantarray; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
447 @$out; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
448 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
449 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
450 sub getElementsByAttribute { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
451 my $element = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
452 my $key = lc(shift); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
453 my $val = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
454 my ( $flat, $cur ) = @$element; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
455 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
456 my $out = []; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
457 for ( ; $cur <= $#$flat ; $cur++ ) { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
458 next if $flat->[$cur]->[000]; # close |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
459 my $elem = HTML::TagParser::Element->new( $flat, $cur ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
460 my $attr = $elem->attributes(); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
461 next unless exists $attr->{$key}; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
462 next if ( $attr->{$key} ne $val ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
463 return $elem unless wantarray; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
464 push( @$out, $elem ); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
465 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
466 return unless wantarray; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
467 @$out; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
468 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
469 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
470 1; |