Created
May 25, 2010 04:58
-
-
Save tomill/412780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Config::Pit; | |
use HTTP::Cookies; | |
use URI; | |
use WWW::Mechanize; | |
use XML::LibXML; | |
use App::Options( | |
option => { | |
realm => 'type=string; required=1;', | |
name => 'type=string; required=1;', | |
query => 'type=string; required=1;', | |
}, | |
); | |
=head1 SYNOPSIS | |
perl wow-auction-alert.pl --realm=Foo --name=Myname --query="Cured Rugged Hide" | |
=cut | |
my $agent = new WWW::Mechanize( | |
autocheck => 1, | |
agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', | |
timeout => 10, | |
cookie_jar => HTTP::Cookies->new( | |
file => 'cookie.txt', | |
autosave => 1, | |
), | |
); | |
my $url = new URI('http://www.wowarmory.com/auctionhouse/search/?sort=buyout&reverse=false&pageSize=20&qual=0&end=20&rhtml=true&f=1'); | |
$url->query_form( | |
$url->query_form, | |
cn => $App::options{name}, | |
r => $App::options{realm}, | |
n => $App::options{query}, | |
); | |
$agent->get($url); | |
if ($agent->content =~ />You must log in.</) { | |
my $conf = Config::Pit::pit_get('battle.net', require => { | |
username => 'battle.net ID', | |
password => 'battle.net password' | |
}); | |
$agent->get('https://us.battle.net/login/login.xml?cr=true&ref=http://www.wowarmory.com/index.xml&app=armory'); | |
$agent->submit_form(fields => { | |
accountName => $conf->{username}, | |
password => $conf->{password}, | |
}); | |
$agent->get($url); | |
} | |
my $count = do { | |
my ($count) = $agent->content =~ /<auctionSearch.+?total="(\d+)">/; | |
$count; | |
}; | |
if ($count > 0) { | |
print "$App::options{name}\@$App::options{realm}: $App::options{query} - $count\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment