Mercurial > eagle-eye
diff Ikariam.pm @ 154:637314cc57ed
checking for friends.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sat, 01 Nov 2008 05:05:15 +0800 |
parents | fab1593cadf1 |
children | 2efa901871e5 ba03aa8abdb2 |
line wrap: on
line diff
--- a/Ikariam.pm Sat Nov 01 03:52:09 2008 +0800 +++ b/Ikariam.pm Sat Nov 01 05:05:15 2008 +0800 @@ -95,6 +95,7 @@ use strict; use Data::Dumper; use LWP; + use HTTP::Cookies; use WWW::Mechanize; use XML::LibXML qw(:encoding); @@ -142,7 +143,7 @@ # if debug - # LWP::Debug::level('+conns'); + # LWP::Debug::level('+trace'); $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); @@ -739,6 +740,39 @@ } } +sub checkFriends +{ + # must check cities first, so we know if we have a museum available. + my $self = shift; + + foreach my $cityId (keys(%{$self->{'cities'}})) { + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (0..$#locations) { + if($locations[$_] eq 'museum') { + my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=museum&id=%d&position=%d', $self->{server}, $cityId, $_ )); + my @hrefs = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="content"]/table/tbody/tr/td/a[1]/@href'); + foreach my $href (@hrefs) { + if ($href =~ /&id=(\d+)&/) { + $self->{'friends'}->{$1} = undef; + } + } + last; + } + } + } + + if(-f "friends.txt") { + # load friends + open(IN, "friends.txt") or die "Unable to open friends.txt\n"; + while(<IN>) { + chomp; + my $friend = Ikariam::User->retrieve(name => $_); + $self->{friends}->{$friend->id} = undef if(defined($friend)); + } + close(IN); + } +} + sub check { my $self = shift;