Mercurial > eagle-eye
view scan.pl @ 14:8b7bc598ba06
we now also save user's profile when scanning islands.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 08 Oct 2008 12:18:50 +0800 |
parents | f590b5ea5e55 |
children | 59f2c435760c |
line wrap: on
line source
#!/usr/bin/perl use strict; use Data::Dumper; use Ikariam; package main; sub saveCities { my ($island, @cities) = @_; foreach my $city (@cities) { $city->{island} = $island; if(my $c = Ikariam::Cities->retrieve($city->{cityId})) { foreach my $i (keys(%$city)) { eval($c->$i($city->{$i})); # printf("%s %s ", $i, $city->{$i}); } # print ("\n"); $c->autoupdate(1); $c->update(); } else { Ikariam::Cities->insert($city); } printf("city %d %s saved\n", $city->{cityId}, $city->{cityname}); # Download user profile. foreach my $x (qw/score army_score_main trader_score_secondary/) { my $users = $::i->viewScore($x, $city->{owner}, 0); saveUser($users); } } } sub saveUser { my $users = shift; foreach my $user (values(%{$users})) { # print(Dumper($user)); printf("Saving user %s\n", $user->{'name'}); if(my $c = Ikariam::User->retrieve($user->{id})) { foreach my $i (keys(%$user)) { eval($c->$i($user->{$i})); } $c->autoupdate(1); $c->update(); } else { Ikariam::User->insert($user); } } } our $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); my @islands; if($#ARGV == 1) { $i->login; @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); } elsif($#ARGV == 0) { $i->login; my $island = $ARGV[0]; my @cities = $i->viewIsland($island); saveCities($island, @cities); $i->logout; return; } elsif($#ARGV == -1) { $i->login; @islands = $i->viewHomeMap(); } else { die("Usage: $0\nUsage: $0 x y\n"); } foreach my $island (@islands) { printf("checking island %d\n", $island->{id}); if(my $c = Ikariam::Island->retrieve($island->{id})) { foreach my $i (keys(%$island)) { eval($c->$i($island->{$i})); } } else { Ikariam::Island->insert($island); } # scanning the island my @cities = $i->viewIsland($island->{id}); saveCities($island->{id}, @cities); } $i->logout; # $i->getCityInfo();