Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RubyでAmazon APIを使ってKindle Unlimited本の一覧を取得
# coding: UTF-8
require 'rubygems'
require 'amazon/ecs'
Amazon::Ecs.options = {
:associate_tag => [Amazonアソシエイトタグ],
:AWS_access_key_id => [AWSアクセスキーID],
:AWS_secret_key => [AWSシークレットキー]
}
KINDLE_UMLIMITED_BROWSE_NODE_ID = 4486610051
books = Array.new
search_word = ARGV[0] || 'ruby'
max_page_count = ARGV[1].to_i || 10
i = 0
while max_page_count > i do
sleep 2
puts "処理待ちです。しばらくお待ちください。"
begin
res = Amazon::Ecs.item_search(search_word, {:search_index => 'KindleStore', :browse_node => KINDLE_UMLIMITED_BROWSE_NODE_ID, :response_group => 'ItemAttributes', :country => 'jp', :ItemPage => i+1})
rescue
puts "取得に失敗しました。再取得を行います.."
next
end
res.items.each do |item|
books << { Title: item.get('ItemAttributes/Title'), Author: item.get('ItemAttributes/Author') }
end
i += 1
end
books.each do |item|
puts "タイトル:" + item[:Title].to_s + " 作者:" + item[:Author].to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.