Mercurial > eagle-eye
comparison Ikariam.pm @ 298:b3b845d30d4b
new cache mechanism
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 07 Dec 2008 16:40:04 +0800 |
parents | 1d0a55318262 |
children | 58b36b18809f |
comparison
equal
deleted
inserted
replaced
297:073442284ec1 | 298:b3b845d30d4b |
---|---|
111 use LWP; | 111 use LWP; |
112 | 112 |
113 use HTTP::Cookies; | 113 use HTTP::Cookies; |
114 use WWW::Mechanize; | 114 use WWW::Mechanize; |
115 use XML::LibXML qw(:encoding); | 115 use XML::LibXML qw(:encoding); |
116 use YAML qw/LoadFile Dump DumpFile/; | |
116 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; | 117 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; |
117 use POSIX; | 118 use POSIX; |
118 use utf8; | 119 use utf8; |
119 | 120 |
120 sub new | 121 sub new |
130 server => $server, | 131 server => $server, |
131 user => $user, | 132 user => $user, |
132 pass => $pass, | 133 pass => $pass, |
133 debug => undef, | 134 debug => undef, |
134 }; | 135 }; |
136 | |
135 | 137 |
136 # if debug | 138 # if debug |
137 LWP::Debug::level('+trace'); | 139 LWP::Debug::level('+trace'); |
138 | 140 |
139 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-$server-cookies.txt", autosave => 1, ignore_discard => 1)); | 141 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-$server-cookies.txt", autosave => 1, ignore_discard => 1)); |
1296 my @cities = Ikariam::Extractor->new(content => $res->content)->find('//option[@class="avatarCities coords"]/@value'); | 1298 my @cities = Ikariam::Extractor->new(content => $res->content)->find('//option[@class="avatarCities coords"]/@value'); |
1297 | 1299 |
1298 if($#cities<0) { | 1300 if($#cities<0) { |
1299 die ("login failed\n"); | 1301 die ("login failed\n"); |
1300 } | 1302 } |
1301 foreach(@cities) { | 1303 foreach (@cities) { |
1302 $self->{'cities'}->{$_} = {}; | 1304 $self->{'cities'}->{$_} = {}; |
1303 $self->{'cities'}->{$_}->{id} = $_; | 1305 $self->{'cities'}->{$_}->{id} = $_; |
1306 if(-f "city-$_-dump.yaml") { | |
1307 $self->{'cities'}->{$_} = LoadFile("city-$_-dump.yaml"); | |
1308 } | |
1304 } | 1309 } |
1305 } | 1310 } |
1306 | 1311 |
1307 | 1312 |
1308 1; | 1313 1; |