AmazonのWebサービスを活用してASIN記法をはき出すPerlスクリプト

May 29, 2009   #Perl  :

先日の続きと言うことで、さっそく作ってみました。

#!/opt/local/bin/perl
# === Libraries ===
use strict;
use warnings;
use LWP::UserAgent;
use URI::Amazon::APA;
use XML::Simple;
use YAML::Syck;
# === 起動時の処理 ===
exit if ( @ARGV ==  );
exit unless ( $ARGV[] =~ /\d\d\d\d\d\d\d\d\d\d\d\d\d/ );
# === Main part ===
my $u = URI::Amazon::APA->new('http://ecs.amazonaws.jp/onca/xml');
$u->query_form(
Service     => 'AWSECommerceService',
Operation   => 'ItemLookup',
ItemId      => shift || '9784798118925',
IdType      => 'EAN',
SearchIndex => 'Books',
);
$u->sign(
key    => キー,
secret => 秘密鍵,
);
my $ua = LWP::UserAgent->new;
my $r  = $ua->get($u);
die "Item not found.\n"
if ( not( exists( XMLin( $r->content )->{Items}->{Item}->{ASIN} ) ) );
print("[asin:");
print XMLin( $r->content )->{Items}->{Item}->{ASIN};
print(":title]\n");

実行例

~/bin on simoom634 [535] $: ./access_amazon.pl 9784798118926
Item not found.
~/bin on simoom634 [536] $: ./access_amazon.pl 9784798118925
[asin:4798118923:title]

「amazon」に関連する最近のエントリ