Mercurial > eagle-eye
comparison 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 |
comparison
equal
deleted
inserted
replaced
150:fab1593cadf1 | 154:637314cc57ed |
---|---|
93 | 93 |
94 package Ikariam; | 94 package Ikariam; |
95 use strict; | 95 use strict; |
96 use Data::Dumper; | 96 use Data::Dumper; |
97 use LWP; | 97 use LWP; |
98 | |
98 use HTTP::Cookies; | 99 use HTTP::Cookies; |
99 use WWW::Mechanize; | 100 use WWW::Mechanize; |
100 use XML::LibXML qw(:encoding); | 101 use XML::LibXML qw(:encoding); |
101 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; | 102 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; |
102 use POSIX; | 103 use POSIX; |
140 } | 141 } |
141 }; | 142 }; |
142 | 143 |
143 | 144 |
144 # if debug | 145 # if debug |
145 # LWP::Debug::level('+conns'); | 146 # LWP::Debug::level('+trace'); |
146 | 147 |
147 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); | 148 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); |
148 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); | 149 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); |
149 | 150 |
150 return bless $self, $class; | 151 return bless $self, $class; |
734 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = 0; | 735 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = 0; |
735 } else { | 736 } else { |
736 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = $numbers[$j]; | 737 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = $numbers[$j]; |
737 } | 738 } |
738 } | 739 } |
740 } | |
741 } | |
742 | |
743 sub checkFriends | |
744 { | |
745 # must check cities first, so we know if we have a museum available. | |
746 my $self = shift; | |
747 | |
748 foreach my $cityId (keys(%{$self->{'cities'}})) { | |
749 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; | |
750 foreach (0..$#locations) { | |
751 if($locations[$_] eq 'museum') { | |
752 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=museum&id=%d&position=%d', $self->{server}, $cityId, $_ )); | |
753 my @hrefs = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="content"]/table/tbody/tr/td/a[1]/@href'); | |
754 foreach my $href (@hrefs) { | |
755 if ($href =~ /&id=(\d+)&/) { | |
756 $self->{'friends'}->{$1} = undef; | |
757 } | |
758 } | |
759 last; | |
760 } | |
761 } | |
762 } | |
763 | |
764 if(-f "friends.txt") { | |
765 # load friends | |
766 open(IN, "friends.txt") or die "Unable to open friends.txt\n"; | |
767 while(<IN>) { | |
768 chomp; | |
769 my $friend = Ikariam::User->retrieve(name => $_); | |
770 $self->{friends}->{$friend->id} = undef if(defined($friend)); | |
771 } | |
772 close(IN); | |
739 } | 773 } |
740 } | 774 } |
741 | 775 |
742 sub check | 776 sub check |
743 { | 777 { |