Mercurial > eagle-eye
comparison disturb.pl @ 362:7f38a5cb769e
dirtry trick
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Mon, 23 Feb 2009 16:26:47 +0800 |
parents | |
children | 7274d8f41d5f |
comparison
equal
deleted
inserted
replaced
361:81a2aeaf6bf7 | 362:7f38a5cb769e |
---|---|
1 #!/usr/bin/perl | |
2 use strict; | |
3 use Ikariam; | |
4 use Data::Dumper; | |
5 package main; | |
6 my $ikariam = new Ikariam($::server, $::user, $::pass); | |
7 | |
8 if($#ARGV != 2) { die("Usage: $0 blockadeCity myCity travelTime\n"); } | |
9 my ($blockadeCity, $myCity, $travelTime) = @ARGV; | |
10 | |
11 LOOP: while(1) { | |
12 $ikariam->login; | |
13 # delete the old event, and launch a new one. | |
14 my $res = $ikariam->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $::server)); | |
15 my $extractor = new Ikariam::Extractor(content => $res->content); | |
16 my $result = $extractor->{doc}->find(sprintf('//table[@class="locationEvents"]//tr[position() > 1]', $_)); | |
17 foreach my $div ( @$result ) { | |
18 my $extractor = new Ikariam::Extractor(content => $div->toString(1)); | |
19 my $f = $extractor->find('//td[4]/a/@href'); | |
20 my $t = $extractor->find('//td[8]/a/@href'); | |
21 my $from_city = $1 if($f =~ /\?view=island&cityId=(\d+)/); | |
22 my $to_city = $1 if($t =~ /\?view=island&cityId=(\d+)/); | |
23 | |
24 if($from_city == $myCity && $to_city == $blockadeCity) { | |
25 # Cancel the last attack | |
26 $ikariam->{mech}->get(sprintf("http://%s/index.php%s", $::server, $extractor->find('//td[9]/a/@href'))); | |
27 | |
28 # Create a new one. | |
29 $ikariam->changeCity($myCity); | |
30 $ikariam->blockadeCity($blockadeCity, { | |
31 blockadeDuration => 8*60*60, | |
32 cargo_fleet_211 => 1, # Flamethrower | |
33 }); | |
34 $ikariam->logout; | |
35 | |
36 sleep($travelTime*60); | |
37 next LOOP; | |
38 } | |
39 } | |
40 | |
41 $ikariam->login; | |
42 $ikariam->changeCity($myCity); | |
43 $ikariam->blockadeCity($blockadeCity, { | |
44 blockadeDuration => 8*60*60, | |
45 cargo_fleet_211 => 1, # Flamethrower | |
46 }); | |
47 $ikariam->logout; | |
48 sleep($travelTime*60); | |
49 } |