comparison scores.pl @ 5:dbb97c4265ba

implemented the scores search tool
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 01:51:28 +0800
parents
children 2040ccc95670
comparison
equal deleted inserted replaced
4:c0287e8ff168 5:dbb97c4265ba
1 #!/usr/bin/perl
2 use strict;
3 use Ikariam;
4 use Data::Dumper;
5
6 package main;
7
8 sub saveUser
9 {
10 my $users = shift;
11 foreach my $user (values(%{$users}))
12 {
13 if(my $c = Ikariam::Users->retrieve($user->{id}))
14 {
15 foreach my $i (keys(%$user)) {
16 eval($c->$i($user->{$i}));
17 }
18 $c->autoupdate(1);
19 $c->update();
20 } else {
21 Ikariam::Users->insert($user);
22 }
23 }
24 }
25
26 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
27 # $i->login;
28 if($#ARGV == 0) {
29 my $users;
30 foreach my $x (qw/score army_score_main trader_score_secondary/)
31 {
32 $users = $i->viewScore($x, $ARGV[0], 0);
33 saveUser($users);
34 }
35 } else {
36 my $users = $i->viewScore('army_score_main');
37 saveUser($users);
38 # die("Usage: $0 nickname\n");
39 }
40
41 # highscoreType
42 # <option value="score">總積分</option>
43 # <option value="building_score_main">建築大師</option>
44 # <option value="building_score_secondary">建築等級</option>
45 # <option value="research_score_main">科學巨人</option>
46 # <option value="research_score_secondary">研究等級</option>
47 # <option value="army_score_main" selected="selected">戰爭將軍</option>
48 # <option value="trader_score_secondary">黃金存量</option>
49 # my $users = $i->viewScore('score', 'chihchun', '0');