Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

davorg (18)

davorg
  dave@dave.org.uk
http://dave.org.uk/
Yahoo! ID: daveorguk (Add User, Send Message)

Hacker, author, trainer

Technorati Profile [technorati.com]

Journal of davorg (18)

Friday January 21, 2005
07:14 AM

Amazon Web Services

[ #22825 ]

Like acme , I've been playing with Amazon Web Services. I decided that I've not been reading enough books, so I've set myself a target of reading fifty books this year. I've got a database table where I store the ISBNs of books I'm reading and I use Amazon Web Services to grab more details of the books from Amazon. Net::Amazon and Class::DBI make this trivial.

#!/usr/bin/perl

use Net::Amazon;
use Cache::File;
use Books;

@ARGV || die "No ISBN given\n";

my %az_opt = (
              token        => "MY AMAZON WEB SERVICE ID",
              locale       => 'uk',
              affiliate_id => "davblog-21",
              cache        => Cache::File->new(
                                               cache_root
                                               => '/tmp/amzn_cache',
                                               cache_umask     => 000,
                                               default_expires => '30 day',
                                              ),
             );

my $amz = Net::Amazon->new(%az_opt);

foreach (@ARGV) {
  my $isbn = sprintf "%010s", $_;
  my $resp = $amz->search( asin => $isbn );
  die "Can't find $isbn" unless $resp->is_success;
  my ($prop) = $resp->properties;

  print $prop->title, "\n";
  print ' - ', join (', ', $prop->authors), "\n";
  print $prop->url, "\n";
  print $prop->ImageUrlSmall, "\n";
  print "\n";

  my $book = Books::Book->create(
                                 {
                                  isbn => $isbn,
                                  title => $prop->title,
                                  author => join (', ', $prop->authors),
                                  url => $prop->url,
                                  cover_url => $prop->ImageUrlSmall,
                                  md_cover_url => $prop->ImageUrlMedium,
                                  lg_cover_url => $prop->ImageUrlLarge
                                 }
                                );
}

Some of this code comes from a similar application that Tony Bowden has written. Books.pm is a Class::DBI module which includes classes for the various tables in my database.

Having got this data into the database along with details of the dates I started and finished reading each book, it becomes simple to create a page that shows what I'm reading. There are also RSS feeds which I use to power the "Reading List" section on the front page of my blog.

All in all, a very satisfying couple of hours work.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.