Amazon Web Services

inkdroid on 2003-01-03T15:02:05

Intruiged after I saw brian d foy's journal entry on Amazon's Web Services I registered for a developer token [free], and wrote a program to pull down my wishlist periodically for my personal website.

LWP::Simple and XML::Simple made this so simple I had to paste the code here

#!/usr/local/bin/perl

use strict;
use LWP::Simple;
use XML::Simple;

## fetch the wishlist from amazon

my $token = 'YOUR DEVELOPERS TOKEN HERE';
my $wishlistId = 'YOUR WISHLIST ID HERE';
my $host = 'xml.amazon.com';
my $path = 'onca/xml2';
my $query =
   "t=webservices-20" .
   "&dev-t=$token" .
   "&type=heavy" .
   "&f=xml" .
   "&WishlistSearch=$wishlistId";

my $wishlist = XMLin( get( "http://$host/$path?$query" ) );

## write out paltry HTML

foreach my $item (@{ $wishlist->{ Details } } ) {

   my $isbn = $item->{ Isbn };
   my $title = $item->{ ProductName };
   my $author = $item->{ Authors }{ Author };
   $author = $author->[0] if ( ref( $author ) eq 'ARRAY' );
   my $publisher = $item->{ Manufacturer };
   my $img = $item->{ ImageUrlSmall };
   $img = qq(<IMG SRC="$img" BORDER=0 ALIGN="left">) if $img;
   my $listPrice = $item->{ ListPrice };
   my $amazonPrice = $item->{ OurPrice };
   my $usedPrice = $item->{ UsedPrice } || 'n/a';
   my $url = $item->{ url };

   print

<<ITEM;
<A HREF="$url">$title</a> by $author
$img
<B>Publisher:</B> $publisher <BR>
<B>ISBN:</B> $isbn <BR>
<B>List:</B> $listPrice <BR>
<B>Amazon:</B> $amazonPrice <BR>
<B>Used:</B> $usedPrice <BR><BR>
ITEM

}