Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment