comparison scan.pl @ 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 fd44e3a1f800
children 552528bb4917
comparison
equal deleted inserted replaced
19:9c52ae71c1cb 20:5635e75c92d0
25 } else { 25 } else {
26 Ikariam::Cities->insert($city); 26 Ikariam::Cities->insert($city);
27 } 27 }
28 28
29 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname}); 29 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname});
30 30 if(my $user = Ikariam::User->retrieve($city->{user}))
31 # Download user profile.
32 foreach my $x (qw/score army_score_main trader_score_secondary/)
33 { 31 {
34 my $users = $::i->viewScore($x, $city->{owner}, 0); 32 if($user->time le (time - 60*60)) {
35 saveUser($users); 33 # Download user profile.
34 foreach my $x (qw/score army_score_main trader_score_secondary/)
35 {
36 my $users = $::i->viewScore($x, $city->{owner}, 0);
37 saveUser($users);
38 }
39 }
36 } 40 }
37 } 41 }
38 } 42 }
39 43
40 sub saveUser 44 sub saveUser
41 { 45 {
42 my $users = shift; 46 my $users = shift;
43 47
44 foreach my $user (values(%{$users})) 48 foreach my $h_user (values(%{$users}))
45 { 49 {
46 # print(Dumper($user)); 50 # print(Dumper($user));
47 printf("Saving user %s\n", $user->{'name'}); 51 printf("Saving user %s\n", $h_user->{'name'});
48 $user->{'time'} = time; 52 $h_user->{'time'} = time;
49 if(my $c = Ikariam::User->retrieve($user->{id})) 53 my $user;
54 if($user = Ikariam::User->retrieve($h_user->{id}))
50 { 55 {
51 foreach my $i (keys(%$user)) { 56 foreach my $i (keys(%$h_user)) {
52 eval($c->$i($user->{$i})); 57 # eval($c->$i($h_user->{$i}));
58 $user->set($i => $h_user->{$i});
53 } 59 }
54 $c->autoupdate(1);
55 $c->update();
56 } else { 60 } else {
57 Ikariam::User->insert($user); 61 $user = Ikariam::User->insert($h_user);
58 } 62 }
63 $user->update();
59 } 64 }
60 } 65 }
61 66
62 our $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); 67 our $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
63 68