# HG changeset patch # User "Rex Tsai " # Date 1225487115 -28800 # Node ID 637314cc57ed1fb0d12bd7a9237960b726e55e45 # Parent fab1593cadf1f1ed628246905be61c0756c0386f checking for friends. diff -r fab1593cadf1 -r 637314cc57ed Ikariam.pm --- 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() { + chomp; + my $friend = Ikariam::User->retrieve(name => $_); + $self->{friends}->{$friend->id} = undef if(defined($friend)); + } + close(IN); + } +} + sub check { my $self = shift;