Created
November 27, 2016 12:03
-
-
Save TSKGunGun/3c02200800c442764f6f487eec95adfb to your computer and use it in GitHub Desktop.
RubyでAmazon APIを使ってKindle Unlimited本の一覧を取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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