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.