amazon ECS

「査収」エントリで書名メモから asin を取得。amazon-ecs を使ってみた。

require 'kconv'

require 'rubygems'
require 'amazon/ecs'

Amazon::Ecs.options = {
  :aWS_access_key_id => ["xxxxxxxxxxxxxxxxxxxxx"], # Your Access Key ID
  :associate_tag => "xxxxxxxx-22", #Associate ID
  :country => :jp
}

text = "スサノオ自伝
中島敦全集2 文庫
東京の戦争 吉村昭 文庫
ドイツの歴史 ふくろうの本
バルカンの歴史 ふくろうの本
世界紛争 軍備地図"

opt = {:response_group => 'Medium', :sort => 'salesrank'}

text.split("\n").each do |line|
  print "#{line.toeuc}...\n"
  res = Amazon::Ecs.item_search(line.toutf8, opt)
  res.items.each do |item|
    puts "- #{item.get('title').toeuc}, [asin:#{item.get('asin').toeuc}]\n"
  end
end

ファイルから読むよう実装してもいいけど、小道具なんでこれでいいや。

スサノオ自伝...

中島敦全集2 文庫...

東京の戦争 吉村昭 文庫...

ドイツの歴史 ふくろうの本...

バルカンの歴史 ふくろうの本...

世界紛争 軍備地図...

  • 最新版アトラス 世界紛争・軍備地図 (アトラス 最新版), asin:4843309982

と候補がでてくるので、当てはまるのだけを残してあとは消す。