changeset 16:59f2c435760c

implemented cached by timing.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 15:24:21 +0800
parents e68f4cadfabd
children 5ea88404dc74
files Ikariam.pm scan.pl
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Wed Oct 08 12:56:40 2008 +0800
+++ b/Ikariam.pm	Wed Oct 08 15:24:21 2008 +0800
@@ -25,7 +25,10 @@
 
     my $self =
     {
-        mech => WWW::Mechanize->new(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)"),
+        mech => WWW::Mechanize->new(
+            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)",
+            timeout => 10,
+        ),
         server => $server,
         user => $user,
         pass => $pass,
--- a/scan.pl	Wed Oct 08 12:56:40 2008 +0800
+++ b/scan.pl	Wed Oct 08 15:24:21 2008 +0800
@@ -11,6 +11,7 @@
     foreach my $city (@cities)
     {
         $city->{island} = $island;
+        $city->{'time'} = time;
         if(my $c = Ikariam::Cities->retrieve($city->{cityId}))
         {
             foreach my $i (keys(%$city)) {
@@ -44,6 +45,7 @@
     {
         # print(Dumper($user));
         printf("Saving user %s\n", $user->{'name'});
+        $user->{'time'} = time;
         if(my $c = Ikariam::User->retrieve($user->{id}))
         {
             foreach my $i (keys(%$user)) {
@@ -81,17 +83,22 @@
 foreach my $island (@islands)
 {
     printf("checking island %d\n", $island->{id});
-    if(my $c = Ikariam::Island->retrieve($island->{id})) {
-        foreach my $i (keys(%$island)) {
-            eval($c->$i($island->{$i}));
-        }
-    } else {
-        Ikariam::Island->insert($island);
-    }
 
     # scanning the island
-    my @cities = $i->viewIsland($island->{id});
-    saveCities($island->{id}, @cities);
+    if($island->{time} < (time - 60*60*12 ))
+    {
+        my @cities = $i->viewIsland($island->{id});
+        saveCities($island->{id}, @cities);
+
+        $island->{'time'} = time;
+        if(my $c = Ikariam::Island->retrieve($island->{id})) {
+            foreach my $i (keys(%$island)) {
+                eval($c->$i($island->{$i}));
+            }
+        } else {
+            Ikariam::Island->insert($island);
+        }
+    }
 }
 $i->logout;
 # $i->getCityInfo();