diff scores.pl @ 7:2040ccc95670

implemented scores collection.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 02:50:19 +0800
parents dbb97c4265ba
children e4b3168d0319
line wrap: on
line diff
--- a/scores.pl	Wed Oct 08 01:52:18 2008 +0800
+++ b/scores.pl	Wed Oct 08 02:50:19 2008 +0800
@@ -10,6 +10,7 @@
     my $users = shift;
     foreach my $user (values(%{$users}))
     {
+        printf("Saving %s\n", $user->{'name'});
         if(my $c = Ikariam::Users->retrieve($user->{id}))
         {
             foreach my $i (keys(%$user)) {
@@ -24,7 +25,8 @@
 }
 
 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
-# $i->login;
+$i->login;
+
 if($#ARGV == 0) {
     my $users;
     foreach my $x (qw/score army_score_main trader_score_secondary/)
@@ -32,10 +34,42 @@
         $users = $i->viewScore($x, $ARGV[0], 0);
         saveUser($users);
     }
+} elsif ($#ARGV == 1) {
+    # search the islands and cities nearby
+    my ($x, $y) = @ARGV;
+    my $offset = 5;
+
+    Ikariam::Island->has_many(cities => 'Ikariam::Cities');
+
+    my @islands = Ikariam::Island->retrieve_from_sql(
+        "x >= " . ($x - $offset) . " AND " . " x <= " . ($x + $offset) . 
+        " AND " .
+        "y >= " . ($y - $offset) . " AND " . " y <= " . ($y + $offset)
+    );
+
+    my %owners;
+    foreach my $island (@islands)
+    {
+        my @cities = $island->cities;
+        foreach my $city (@cities)
+        {
+            $owners{$city->owner} += 1;
+        }
+    }
+
+
+    foreach my $o (keys(%owners))
+    {
+        foreach my $x (qw/score army_score_main trader_score_secondary/)
+        {
+            my $users = $i->viewScore($x, $o, 0);
+            saveUser($users);
+        }
+    }
 } else {
-    my $users = $i->viewScore('army_score_main');
-    saveUser($users);
-    # die("Usage: $0 nickname\n");
+    # my $users = $i->viewScore('army_score_main');
+    # saveUser($users);
+    die("Usage: $0 nickname\n");
 }
 
 # highscoreType