Skip to content

Instantly share code, notes, and snippets.

@ctbarna
Created August 30, 2011 20:41
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 ctbarna/1181964 to your computer and use it in GitHub Desktop.
Save ctbarna/1181964 to your computer and use it in GitHub Desktop.
A little script I wrote to download images from Amazon.
# Download book covers from Amazon.
# Requires asin gem.
require 'net/http'
require 'asin'
client = ASIN::Client.instance
# Images Folder
IMG_DIR = ""
# API credentials
API_KEY = ''
SECRET_KEY = ''
ASIN::Configuration.configure do |config|
config.secret = SECRET_KEY
config.key = API_KEY
end
if ARGV.empty?
raise "You didn't search for anything"
end
puts "Searching for: " + ARGV[0]
items = client.search_keywords ARGV[0]
items.each_with_index do |book, i|
count = i+1
puts count.to_s + ". " + book.title
end
print "Select one: "
selected = STDIN.gets.chomp.to_i - 1
puts "Getting: " + items[selected].title
uri = URI.parse(items[selected].raw.LargeImage.URL)
Net::HTTP.start(uri.host, uri.port) do |http|
resp = http.get(uri.path)
open(IMG_DIR + items[selected].title + ".jpg", "wb") do |file|
file.write(resp.body)
end
end
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment