changeset 129:3756298f8e4b

fixed the island and city id in the military reports.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 01:53:57 +0800
parents 3196b1f5dc13
children dbefe10550cb
files Ikariam.pm
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Fri Oct 31 00:51:49 2008 +0800
+++ b/Ikariam.pm	Fri Oct 31 01:53:57 2008 +0800
@@ -578,11 +578,15 @@
     $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]');
     $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]');
 
-    $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()');
-    my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href');
+    # $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()');
+    # my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href');
+    $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()');
+    my $href = $extractor->find('//td[@class="battle"]/a/@href');
     if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) {
        $report{island} = $1;
        $report{city} = $2;
+    } else {
+        die ($href);
     }
     $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]');
     $report{wood} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="wood"]');
@@ -617,19 +621,23 @@
             my $report = Ikariam::Report->retrieve($1);
             if(!$report) {
                 my $report_hash = $self->checkMilitaryAdvisorReportView($1);
-                $report = Ikariam::Report->insert($report_hash);
+                if(defined($report_hash)) {
+                    $report = Ikariam::Report->insert($report_hash);
 
-                if($date =~ /(\d+)\.(\d+)\. (\d+):(\d+)/) {
-                    my $unixtime = mktime (0, $4, $3, $1, ($2-1), '108');
-                    $report->set('date', $unixtime);
+                    if($date =~ /(\d+)\.(\d+)\. (\d+):(\d+)/) {
+                        my $unixtime = mktime (0, $4, $3, $1, ($2-1), '108');
+                        $report->set('date', $unixtime);
+                    }
+                    $report->set('time', time);
+
+                    $report->update();
                 }
-                $report->set('time', time);
-
-                $report->update();
             } else {
+                # we have found the report we like to know, exit the function.
                 return;
             }
         } else {
+            # there is not report yet.
             return;
         }
     }