--- title: AmazonのWebサービスを活用してASIN記法をはき出すPerlスクリプト author: kazu634 date: 2009-05-29 wordtwit_post_info: - 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4619;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}' categories: - 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」に関連する最近のエントリ

最新WebサービスAPIエクスプロ-ラ ~Amazon、はてな、Google、Yahoo! 4大Webサービス完全攻略