comparison Ikariam.pm @ 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 b72786cdccbb
children 2975a94aa7a2
comparison
equal deleted inserted replaced
4:c0287e8ff168 5:dbb97c4265ba
1 #!/usr/bin/env perl 1 #!/usr/bin/env perl
2 2
3 use Class::DBI::AutoLoader ( 3 use Class::DBI::AutoLoader (
4 dsn => 'dbi:SQLite:dbname=ikariam.sqlite', 4 dsn => 'dbi:SQLite:dbname=ikariam.sqlite',
5 options => { RaiseError => 1 }, 5 options => { RaiseError => 1 },
6 tables => ['cities', 'islands'], 6 tables => ['cities', 'islands', 'users'],
7 use_base => 'Class::DBI::SQLite', 7 use_base => 'Class::DBI::SQLite',
8 namespace => 'Ikariam', 8 namespace => 'Ikariam',
9 ); 9 );
10 10
11 package Ikariam; 11 package Ikariam;
32 32
33 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "./cookies.txt", autosave => 1)); 33 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "./cookies.txt", autosave => 1));
34 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); 34 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate');
35 35
36 return bless $self, $class; 36 return bless $self, $class;
37 }
38
39 sub viewScore
40 {
41 my $self = shift;
42 my $type = shift || 'score';
43 my $user = shift || '';
44 my $offset = shift || 0;
45
46 # my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [
47 # highscoreType => $type,
48 # offset => $offset,
49 # searchUser => $user,
50 # view => 'highscore'
51 # ]);
52 #
53 # my $c;
54 # my $status = gunzip \$res->content => \$c
55 # or die "gunzip failed: $GunzipError\n";
56
57 my $c;
58 open(IN, "f");
59 while(<IN>) { $c .= $_;}
60 close(IN);
61 my $html = HTML::TagParser->new($c);
62
63 my ($table) = $html->getElementsByAttribute("class", "table01");
64 my @elems = getElementsByTagName($table, "tr");
65
66 my %users;
67 foreach my $elem (@elems) {
68 my $e;
69 my %user;
70
71 $e = getElementsByAttribute($elem, "class", "action");
72 $e = getElementsByTagName($e, "a");
73
74 if($e->getAttribute('href') =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/)
75 {
76 $user{'id'} = $1;
77
78 $e = getElementsByAttribute($elem, "class", "name");
79 $user{'name'} = $e->innerText();
80
81 $e = getElementsByAttribute($elem, "class", "allytag");
82 $user{'ally'} = $e->innerText();
83
84 $e = getElementsByTagName($e, "a");
85 if($e->getAttribute('href') =~ /\?view=allyPage&allyId=(\d+)/)
86 {
87 $user{'allyId'} = $1;
88 }
89
90 $e = getElementsByAttribute($elem, "class", "score");
91 $user{$type} = $e->innerText();
92 $user{$type} =~ s/,//;
93
94 $users{$user{'id'}} = \%user;
95 } else {
96 next;
97 }
98 }
99
100 return \%users;
37 } 101 }
38 102
39 sub viewWorldMap 103 sub viewWorldMap
40 { 104 {
41 my $self = shift; 105 my $self = shift;
132 my @e = getElementsByTagName($elem, "li"); 196 my @e = getElementsByTagName($elem, "li");
133 $info{'cityname'} = substr($e[0]->innerText(), 8); 197 $info{'cityname'} = substr($e[0]->innerText(), 8);
134 $info{'citylevel'} = substr($e[1]->innerText(), 14); 198 $info{'citylevel'} = substr($e[1]->innerText(), 14);
135 $info{'owner'} = substr($e[2]->innerText(), 8); 199 $info{'owner'} = substr($e[2]->innerText(), 8);
136 $info{'ally'} = substr($e[3]->innerText(), 8); 200 $info{'ally'} = substr($e[3]->innerText(), 8);
201 delete($info{'ally'}) if($info{'ally'} eq '-');
202
137 @e = getElementsByAttribute($elem, "class", "messageSend"); 203 @e = getElementsByAttribute($elem, "class", "messageSend");
138 if ( $e[0]->getAttribute("href") =~ /with=(\d+)&destinationCityId=(\d+)/) 204 if ( $e[0]->getAttribute("href") =~ /with=(\d+)&destinationCityId=(\d+)/)
139 { 205 {
140 $info{'ownerId'} = $1; 206 $info{'ownerId'} = $1;
141 $info{'cityId'} = $2; 207 $info{'cityId'} = $2;