changeset 131:bb7ac505f5e7

merged.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 01:54:33 +0800
parents 2ff3704cca0e (current diff) dbefe10550cb (diff)
children 2bf64daa8a5e
files
diffstat 2 files changed, 19 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Fri Oct 31 01:50:05 2008 +0800
+++ b/Ikariam.pm	Fri Oct 31 01:54:33 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;
         }
     }
--- a/ikariam.sql	Fri Oct 31 01:50:05 2008 +0800
+++ b/ikariam.sql	Fri Oct 31 01:54:33 2008 +0800
@@ -1,19 +1,5 @@
 CREATE TABLE "ally" ("id" INTEGER PRIMARY KEY  NOT NULL , "name" TEXT, "members" INTEGER, "url" TEXT, "time" DATETIME);
-CREATE TABLE cities (
- cityId INTEGER PRIMARY KEY UNIQUE,
- citylevel INTEGER,
- cityname TEXT,
- user INTEGER,
- owner TEXT,
- ally TEXT,
- island INTEGER, "status" CHAR, "time" INTEGER, "allyId" INTEGER);
-CREATE TABLE "island" (
- id BIGINT PRIMARY KEY UNIQUE,
- x INTEGER,
- y INTEGER,
- name TEXT,
- tradegood INTEGER,
- wonder INTEGER,
- people INTEGER, "time" INTEGER);
+CREATE TABLE "cities" ( cityId INTEGER PRIMARY KEY UNIQUE, citylevel INTEGER, cityname TEXT, user INTEGER, owner TEXT, ally TEXT, island INTEGER, "status" CHAR, "time" INTEGER, "allyId" INTEGER);
+CREATE TABLE "island" ( id BIGINT PRIMARY KEY UNIQUE, x INTEGER, y INTEGER, name TEXT, tradegood INTEGER, wonder INTEGER, people INTEGER, "time" INTEGER);
 CREATE TABLE "report" ("id" INTEGER PRIMARY KEY  NOT NULL , "cityLevel" INTEGER, "wallLevel" INTEGER, "attacker" TEXT, "defender" TEXT, "winner" TEXT, "targetCity" TEXT, "island" INTEGER NOT NULL , "city" INTEGER NOT NULL , "gold" INTEGER DEFAULT 0, "wood" INTEGER DEFAULT 0, "crystal" INTEGER DEFAULT 0, "wine" INTEGER DEFAULT 0, "sulfur" INTEGER DEFAULT 0, "date" DATETIME, "time" DATETIME);
 CREATE TABLE "user" ("id" INTEGER PRIMARY KEY ,"name" VARCHAR,"ally" VARCHAR,"allyId" INTEGER,"score" INTEGER,"building_score_main" INTEGER,"building_score_secondary" INTEGER,"research_score_main" INTEGER,"research_score_secondary" INTEGER,"army_score_main" INTEGER,"trader_score_secondary" INTEGER, "time" INTEGER);