diff scores.pl @ 12:0aeb0fe59257

added update owner of cities
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 11:53:43 +0800
parents f590b5ea5e55
children bb6eebd349fc
line wrap: on
line diff
--- a/scores.pl	Wed Oct 08 10:04:54 2008 +0800
+++ b/scores.pl	Wed Oct 08 11:53:43 2008 +0800
@@ -3,6 +3,16 @@
 use Ikariam;
 use Data::Dumper;
 
+# highscoreType	
+# <option value="score">總積分</option>
+# <option value="building_score_main">建築大師</option>
+# <option value="building_score_secondary">建築等級</option>
+# <option value="research_score_main">科學巨人</option>
+# <option value="research_score_secondary">研究等級</option>
+# <option value="army_score_main" selected="selected">戰爭將軍</option>
+# <option value="trader_score_secondary">黃金存量</option>
+# my $users = $i->viewScore('score', 'chihchun', '0');
+
 package main;
 
 sub saveUser
@@ -27,20 +37,16 @@
 }
 
 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
+$i->login;
 
 if($#ARGV == 0) {
-    $i->login;
-
     my $users;
     foreach my $x (qw/score army_score_main trader_score_secondary/)
     {
         $users = $i->viewScore($x, $ARGV[0], 0);
         saveUser($users);
     }
-    $i->logout;
 } elsif ($#ARGV == 1) {
-    $i->login;
-
     # search the islands and cities nearby
     my ($x, $y) = @ARGV;
     my $offset = 5;
@@ -71,19 +77,32 @@
             saveUser($users);
         }
     }
-    $i->logout;
 } else {
-    # my $users = $i->viewScore('army_score_main');
-    # saveUser($users);
-    die("Usage: $0 nickname\nUsage: $0 x y");
+    if(0) { 
+        # Update all the users
+        my @users = Ikariam::User->retrieve_all();
+        foreach my $user (@users) 
+        {
+            printf("%s\n", $user->name);
+            foreach my $type (qw/score army_score_main trader_score_secondary/)
+            {
+                my $users = $i->viewScore($type, $user->name, 0);
+                saveUser($users);
+            }
+        }
+    } else {
+        # Update owner of cities
+        my @cities = Ikariam::Cities->retrieve_all();
+        foreach my $city (@cities) 
+        {
+            printf("%s\n", $city->owner);
+            foreach my $type (qw/score army_score_main trader_score_secondary/)
+            {
+                my $users = $i->viewScore($type, $city->owner, 0);
+                saveUser($users);
+            }
+        }
+    }
+    # die("Usage: $0 nickname\nUsage: $0 x y");
 }
-
-# highscoreType	
-# <option value="score">總積分</option>
-# <option value="building_score_main">建築大師</option>
-# <option value="building_score_secondary">建築等級</option>
-# <option value="research_score_main">科學巨人</option>
-# <option value="research_score_secondary">研究等級</option>
-# <option value="army_score_main" selected="selected">戰爭將軍</option>
-# <option value="trader_score_secondary">黃金存量</option>
-# my $users = $i->viewScore('score', 'chihchun', '0');
+$i->logout;