Skip to content

Instantly share code, notes, and snippets.

@twada

twada/gist:37864

Created Dec 19, 2008
Embed
What would you like to do?
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'amazon/aws/search'
require 'erb'
hatena_template = <<-EOT
*** <%= book.item_attributes.title %>
ASIN:<%= book.asin %>:detail
<a href="http://www.amazon.com/dp/<%= book.asin %>">Amazon.com</a> での平均評価 [<%= rating %>] (<%= total_reviews %> reviewers)
EOT
erb = ERB.new(hatena_template)
doc = Nokogiri::HTML(open('http://www.joltawards.com/finalists.html'))
titles = doc.xpath('//li/em').map {|em| em.text }
rg = Amazon::AWS::ResponseGroup.new('Large')
req = Amazon::AWS::Search::Request.new('### YOUR AccessKeyId ###')
req.locale = 'us'
titles.each do |title|
is = Amazon::AWS::ItemSearch.new('Books', {'Title' => title })
res = req.search(is, rg)
book = res.item_search_response[0].items[0].item[0]
rating = book.customer_reviews.average_rating
total_reviews = book.customer_reviews.total_reviews
puts erb.result(binding)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment