diff 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
line wrap: on
line diff
--- a/Ikariam.pm	Wed Oct 29 01:14:49 2008 +0800
+++ b/Ikariam.pm	Wed Oct 29 02:43:04 2008 +0800
@@ -8,7 +8,7 @@
 use Class::DBI::AutoLoader (
     dsn       => 'dbi:SQLite:dbname=ikariam.sqlite',
     options   => { RaiseError => 1 },
-    tables    => ['cities', 'island', 'user'],
+    tables    => ['cities', 'island', 'user', 'ally'],
     use_base  => 'Class::DBI::SQLite',
     namespace => 'Ikariam',
 );
@@ -143,6 +143,24 @@
     return bless $self, $class;
 }
 
+sub viewAlly
+{
+    my $self = shift;
+    my $allyId = shift;
+
+    my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=allyPage&allyId=%d", $self->{server}, $allyId));
+    my $extractor = new Ikariam::Extractor(content => $res->content);
+
+    my %ally;
+    $ally{'id'} = $allyId;
+    $ally{'name'} = $extractor->find("//table[\@id='allyinfo']/tr[1]/td[2]/text()");
+    $ally{'members'} = $extractor->find("//table[\@id='allyinfo']/tr[2]/td[2]/text()");
+    $ally{'url'} = $extractor->find("//table[\@id='allyinfo']/tr[5]/td[2]/text()");
+    delete($ally{'url'}) if($ally{'url'} eq '-');
+
+    return \%ally;
+}
+
 sub viewScore
 {
     my $self = shift;
@@ -171,7 +189,7 @@
 
             $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()');
             my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href');
-            if($allyHref =~  /\?view=allyPage&allyId=(\d+)/) {
+            if($allyHref =~ /\?view=allyPage&oldView=highscore&allyId=(\d+)/) {
                 $user{'allyId'} = $1;
             }
             $user{$type} = $extractor->find('//td[@class="score"]/text()');