#!/usr/bin/perl # Script Author: Robbie Allen (rallen@rallenhome.com) # Aug 2003 use warnings; use strict; use Mail::Sender; use Net::Amazon; use Net::Amazon::Request::ASIN; use Log::Log4perl qw(:easy); #### CONFIGURATION SECTION #### # Uncomment line below to see requests sent to Amazon (for debugging) # Log::Log4perl->easy_init({level => $INFO, layout => '%F{1}-%L: %m%n'}); # Set to a true value to send output to email, # otherwise it will go to stdout my $send_email = 1; # Email configuration my $email_addr = 'me@foobar.com'; my $smtp_server = 'mail.foobar.com'; # Set to a true value to compute the sales rankings of all the books # for a given author (defined by $oreilly_author_name) my $do_oreilly_ranking = 1; # Set to the name of the author to find O'Reilly books for my $oreilly_author_name = "Robbie.*Allen"; # List of ASINs of books to retrieve the status for my @asins = ( '0596004648', # AD Cookbook '0596004664', # AD2e '0596005628', # DNS on W2K3 '0672321254', # Managing Enterprise AD '1565926382', # W2K AD '0596002300', # DNS on W2k '0201616211', # Inside AD '0735618674', # MS Windows Scripting Guide '0782141307', # Mastering W2K3 ); #### END CONFIGURATION #### my $ua = Net::Amazon->new( token => 'D1K1WYDVZVOHGI', max_pages => 100, ); my $info = ""; # O'Reilly sales ranking if ($do_oreilly_ranking) { $info .= "O'Reilly Sales Ranking:\n\n"; my $req = Net::Amazon::Request->new( type => 'lite', mode => 'books', # BrowseNodeSearch => 69860, PowerSearch => "publisher:o'reilly", sort => '+salesrank', ); # Response is Net::Amazon::Response my $resp = $ua->request($req); if($resp->is_success()) { my $count = 0; foreach my $book ( @{$resp->xmlref->{Details}} ) { $count++; if ($book->{Authors}->{Author}) { if (ref $book->{Authors}->{Author} && grep /$oreilly_author_name/, @{$book->{Authors}->{Author}} ) { $info .= " $count. " . $book->{ProductName} . "\n"; } elsif ( (not (ref $book->{Authors}->{Author})) && $book->{Authors}->{Author} =~ /$oreilly_author_name/) { $info .= " $count. " . $book->{ProductName} . "\n"; } } } # print $resp->as_string; # $info .= " Book Title: " . scalar $resp->xmlref->{'Details'}->[0]->{'ProductName'} . "\n"; } else { print "Error retrieving page: ", $resp->message(), "\n"; } $info .= "\n" . "-" x 25 . "\n\n"; } $info .= "Book status:\n\n"; foreach my $asin (@asins) { my $req = Net::Amazon::Request::ASIN->new( asin => $asin, type => 'heavy', ); # Response is Net::Amazon::ASIN::Response my $resp = $ua->request($req); use Data::Dumper; if($resp->is_success()) { $info .= " Book Title: " . scalar $resp->xmlref->{'Details'}->[0]->{'ProductName'} . "\n" . " Sales Rank: " . scalar $resp->xmlref->{'Details'}->[0]->{'SalesRank'}. "\n" . " # of Reviews: " . scalar $resp->xmlref->{'Details'}->[0]->{'Reviews'}->{'TotalCustomerReviews'} . "\n" . " Avg Rating: " . scalar $resp->xmlref->{'Details'}->[0]->{'Reviews'}->{'AvgCustomerRating'} . "\n" . "\n"; } else { print "Error retrieving $asin: ", $resp->message(), "\n"; } } if ($send_email) { my $sender = Mail::Sender->new({ from => $email_addr, smtp => $smtp_server }); $sender->Open({ to => $email_addr, subject => "Amazon Book Update for " . scalar localtime }); $sender->Send( $info ); $sender->Close; } else { print $info; }