changeset 20:5635e75c92d0

the user profile is also cached for 1 hour.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 16:56:22 +0800
parents 9c52ae71c1cb
children d5e02a25b000
files enemy.pl scan.pl
diffstat 2 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/enemy.pl	Wed Oct 08 16:22:54 2008 +0800
+++ b/enemy.pl	Wed Oct 08 16:56:22 2008 +0800
@@ -22,6 +22,10 @@
     foreach my $city ($u->cities) {
         my $island = Ikariam::Island->retrieve($city->island);
         printf("Name: %s\n", $city->cityname);
+        if(defined($city->status))
+        {
+            printf("Status: <<<%s>>>\n", $city->status);
+        }
         printf("Level: %s\n", $city->citylevel);
         printf("Island: %s\n", $island->name);
         printf("Location: [%s:%s] http://s2.ikariam.tw/index.php?view=island&id=%s\n", $island->x, $island->y, $island->id);
--- a/scan.pl	Wed Oct 08 16:22:54 2008 +0800
+++ b/scan.pl	Wed Oct 08 16:56:22 2008 +0800
@@ -27,12 +27,16 @@
         }
 
         printf("city %d %s saved\n", $city->{cityId}, $city->{cityname});
-
-        # Download user profile.
-        foreach my $x (qw/score army_score_main trader_score_secondary/)
+        if(my $user = Ikariam::User->retrieve($city->{user}))
         {
-            my $users = $::i->viewScore($x, $city->{owner}, 0);
-            saveUser($users);
+            if($user->time le (time - 60*60)) {
+                # Download user profile.
+                foreach my $x (qw/score army_score_main trader_score_secondary/)
+                {
+                    my $users = $::i->viewScore($x, $city->{owner}, 0);
+                    saveUser($users);
+                }
+            }
         }
     }
 }
@@ -41,21 +45,22 @@
 {
     my $users = shift;
 
-    foreach my $user (values(%{$users}))
+    foreach my $h_user (values(%{$users}))
     {
         # print(Dumper($user));
-        printf("Saving user %s\n", $user->{'name'});
-        $user->{'time'} = time;
-        if(my $c = Ikariam::User->retrieve($user->{id}))
+        printf("Saving user %s\n", $h_user->{'name'});
+        $h_user->{'time'} = time;
+        my $user;
+        if($user = Ikariam::User->retrieve($h_user->{id}))
         {
-            foreach my $i (keys(%$user)) {
-                eval($c->$i($user->{$i}));
+            foreach my $i (keys(%$h_user)) {
+                # eval($c->$i($h_user->{$i}));
+                $user->set($i => $h_user->{$i});
             }
-            $c->autoupdate(1);
-            $c->update();
         } else {
-            Ikariam::User->insert($user);
+            $user = Ikariam::User->insert($h_user);
         }
+        $user->update();
     }
 }