Skip to content

Instantly share code, notes, and snippets.

@talison
Created April 9, 2010 19:38
Show Gist options
  • Save talison/361500 to your computer and use it in GitHub Desktop.
Save talison/361500 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'amazon/aws'
require 'amazon/aws/search'
require 'optparse'
include Amazon::AWS
include Amazon::AWS::Search
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: aws-quicksearch.rb [options]"
opts.on("-t", "--title [TITLE]", "Search for title match") do |t|
options[:Title] = t
end
opts.on("-a", "--author [AUTHOR]", "Search for author match") do |a|
options[:Author] = a
end
opts.on("-n", "--max-items [MAX]", "Set max results") do |m|
options[:max] = m.to_i
end
end.parse!
exit 1 unless (options[:Title] || options[:Author])
is = ItemSearch.new( :Books, {
:MerchantId => 'Amazon',
:Sort => 'salesrank'
}.merge(options.reject { |k,v| k == :max }))
rg = ResponseGroup.new( 'Small' )
req = Request.new
resp = req.search( is, rg )
items = resp.item_search_response[0].items.item
items.each_with_index do |item, idx|
break if options[:max] && idx + 1 > options[:max]
attributes = item.item_attributes[0]
puts "Title: #{attributes.title}"
puts "Author: #{attributes.author.join(', ')}" if attributes.author
puts "Publisher: #{attributes.manufacturer}"
puts "ASIN: #{item.asin}"
puts "URL: #{item.detail_page_url}"
puts "-" * 20
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment