comparison Ikariam.pm @ 98:34749e907405

we now scan for ally
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 29 Oct 2008 02:43:04 +0800
parents 65c102183458
children ed6160630329
comparison
equal deleted inserted replaced
97:5f9bb3042d0c 98:34749e907405
6 } 6 }
7 7
8 use Class::DBI::AutoLoader ( 8 use Class::DBI::AutoLoader (
9 dsn => 'dbi:SQLite:dbname=ikariam.sqlite', 9 dsn => 'dbi:SQLite:dbname=ikariam.sqlite',
10 options => { RaiseError => 1 }, 10 options => { RaiseError => 1 },
11 tables => ['cities', 'island', 'user'], 11 tables => ['cities', 'island', 'user', 'ally'],
12 use_base => 'Class::DBI::SQLite', 12 use_base => 'Class::DBI::SQLite',
13 namespace => 'Ikariam', 13 namespace => 'Ikariam',
14 ); 14 );
15 15
16 package Ikariam::Extractor; 16 package Ikariam::Extractor;
141 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); 141 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate');
142 142
143 return bless $self, $class; 143 return bless $self, $class;
144 } 144 }
145 145
146 sub viewAlly
147 {
148 my $self = shift;
149 my $allyId = shift;
150
151 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=allyPage&allyId=%d", $self->{server}, $allyId));
152 my $extractor = new Ikariam::Extractor(content => $res->content);
153
154 my %ally;
155 $ally{'id'} = $allyId;
156 $ally{'name'} = $extractor->find("//table[\@id='allyinfo']/tr[1]/td[2]/text()");
157 $ally{'members'} = $extractor->find("//table[\@id='allyinfo']/tr[2]/td[2]/text()");
158 $ally{'url'} = $extractor->find("//table[\@id='allyinfo']/tr[5]/td[2]/text()");
159 delete($ally{'url'}) if($ally{'url'} eq '-');
160
161 return \%ally;
162 }
163
146 sub viewScore 164 sub viewScore
147 { 165 {
148 my $self = shift; 166 my $self = shift;
149 my $type = shift || 'score'; 167 my $type = shift || 'score';
150 my $user = shift || ''; 168 my $user = shift || '';
169 # $user{'name'} = $extractor->find('//td[@class="name"]'); 187 # $user{'name'} = $extractor->find('//td[@class="name"]');
170 $user{'name'} = $user; 188 $user{'name'} = $user;
171 189
172 $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()'); 190 $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()');
173 my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href'); 191 my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href');
174 if($allyHref =~ /\?view=allyPage&allyId=(\d+)/) { 192 if($allyHref =~ /\?view=allyPage&oldView=highscore&allyId=(\d+)/) {
175 $user{'allyId'} = $1; 193 $user{'allyId'} = $1;
176 } 194 }
177 $user{$type} = $extractor->find('//td[@class="score"]/text()'); 195 $user{$type} = $extractor->find('//td[@class="score"]/text()');
178 $user{$type} =~ s/,//g; 196 $user{$type} =~ s/,//g;
179 $users{$user{'id'}} = \%user; 197 $users{$user{'id'}} = \%user;