1#!/usr/bin/perl 2###################################################### 3# Power Search 4# Martin Streicher <martin.streicher@apress.com>, 2003 5# Mike Schilli <na@perlmeister.com>, 2003 6###################################################### 7use warnings; 8use strict; 9 10use Net::Amazon; 11use Net::Amazon::Property; 12use Net::Amazon::Request::Power; 13use Getopt::Std; 14 15#use Log::Log4perl qw(:easy); 16#Log::Log4perl->easy_init($DEBUG); 17 18my %opts = (); 19my $usage = "usage: $0 [-s start] [-f finish] phrase [mode]\n". 20 "(use 'subject: perl and author: schwartz' books ". 21 "as an example)\n"; 22 23getopts("s:f:", \%opts) || do {print $usage; exit 1}; 24die $usage 25 if ((!defined $ARGV[0]) || 26 ((exists $opts{s} && exists $opts{f}) && ($opts{f} < $opts{s}))); 27 28my $pagecnt = $opts{s} || 1; 29my $limit = $opts{f} || $opts{s} || 1; 30my $mode = $ARGV[1] || "books"; 31 32my $ua = Net::Amazon->new( 33 associate_tag => $ENV{AMAZON_ASSOCIATE_TAG}, 34 token => $ENV{AMAZON_TOKEN}, 35 secret_key => $ENV{AMAZON_SECRET_KEY}, 36 max_pages => 1, 37); 38 39while ($pagecnt <= $limit) { 40 my $req = Net::Amazon::Request::Power->new( 41 power => $ARGV[0], 42 mode => $mode, 43 page => $pagecnt++, 44 sort => 'inverse-pricerank', 45 node => 377602011, 46 ); 47 48 # Response: Net::Amazon::Power::Response 49 my $resp = $ua->request($req); 50 die "Error" unless $resp->is_success(); 51 last unless $resp->status(); 52 53 for ($resp->properties) { 54 print $_->Asin(), " ", 55 $_->title(), " [", 56 $_->isbn(), "] ", 57 $_->OurPrice(), "\n"; 58 } 59} 60