Created
September 22, 2012 14:40
-
-
Save suwa320/3766361 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'amazon/ecs' | |
BROWSE_NODE = { | |
"apparel" => "361245011", | |
"baby" => "344845011", | |
"books" => "465610", | |
"classical" => "562034", | |
"dvd" => "562004", | |
"electronics" => "3510411", | |
"foreignbooks" => "465610", | |
"healthpersonalcare" => "161669011", | |
"hobbies" => "13331821", | |
"kitchen" => "11717941", | |
"music" => "562032", | |
"software" => "637630", | |
"sportinggoods" => "361245011", | |
"toys" => "13331821", | |
"vhs" => "561972", | |
"video" => "562002", | |
"videogames" => "1060426" | |
} | |
module Amazon | |
class Element | |
def to_hash | |
item_attr = self.get_element('ItemAttributes') | |
authors = item_attr.get_array('Authors') | |
authors = [item_attr.get('Author')] if authors.empty? | |
{ | |
:asin => self.get('ASIN'), | |
:title => item_attr.get('Title'), | |
:authors => authors, | |
:formatted_price => ((self/'ListPrice/FormattedPrice').text rescue ''), | |
:small_image => self.get_hash('SmallImage'), | |
:medium_image => self.get_hash('MediumImage') | |
} | |
end | |
end | |
end | |
Amazon::Ecs.options = { | |
:associate_tag => 'your tag', | |
:AWS_access_key_id => 'your access_key_id', | |
:AWS_secret_key => 'your secret_key', | |
:country => :jp | |
} | |
node_id = ARGV[0].to_s.downcase | |
if BROWSE_NODE.keys.include?(node_id) | |
res = Amazon::Ecs.browse_node_lookup(BROWSE_NODE[node_id], { | |
:response_group => 'TopSellers' | |
}) | |
items = res.doc.search('TopSeller').each_with_object([]) do |v, arr| | |
arr << Amazon::Ecs.item_lookup(v.at('ASIN').text, { | |
:response_group => 'Large' | |
}).items.first.to_hash | |
end | |
items.each_with_index do |item, i| | |
puts "%2d. %s" % [i + 1, item[:title]] | |
end | |
else | |
STDERR.puts "usage: #{File.basename($0)} #{BROWSE_NODE.keys.join('|')}" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment