Skip to content

Instantly share code, notes, and snippets.

@twada
Created December 19, 2008 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twada/37864 to your computer and use it in GitHub Desktop.
Save twada/37864 to your computer and use it in GitHub Desktop.
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