=begin
# install yaz http://www.indexdata.dk/yaz/ :
# ./configure --enable-shared
# make
# sudo make install
#
# install ruby/zoom http://ruby-zoom.rubyforge.org/ :
# ruby extconf.rg
# make
# sudo make install
asin = '0521780195'
book_covers = '/Users/gaspard/book_covers/'
#asin = '0226732169'
#asin = '023945857892' # bad for testing
#require 'zoom'
#
#ZOOM::Connection.open('z3950.loc.gov', 7090) do |conn|
# conn.database_name = 'Voyager'
# conn.preferred_record_syntax = 'USMARC'
# rset = conn.search("@attr 1=7 #{asin}")
# p rset[0]
#end
# using amazon web services :
# access key : 1186KA3K523YWH49MV02
# US : http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=1186KA3K523YWH49MV02&Operation=ItemLookup&IdType=ASIN&ItemId=#{asin}&MerchantId=All&ResponseGroup=Large
require 'net/http' # http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/
url = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=1186KA3K523YWH49MV02&Operation=ItemLookup&IdType=ASIN&ItemId=#{asin}&MerchantId=All&ResponseGroup=Medium"
r = Net::HTTP.get_response( URI.parse( url ) )
# parse xml
require "rexml/document"
include REXML
doc = REXML::Document.new r.body
# error handling
doc.elements.each("ItemLookupResponse/Items/Request/Errors/Error/Message") {|elem| puts elem.text}
# get book info
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/Title"].text
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/Author"].text
#doc.elements.each("ItemLookupResponse/Items/Item/ItemAttributes/Author") {|elem| puts elem.text}
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/NumberOfPages"].text
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/ProductGroup"].text
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/PublicationDate"].text
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/Publisher"].text
# size in cm :
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/PackageDimensions/Length"].text.to_f * 0.0254
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/PackageDimensions/Width"].text.to_f * 0.0254
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/PackageDimensions/Height"].text.to_f * 0.0254
puts doc.elements["ItemLookupResponse/Items/Item/ItemAttributes/PackageDimensions/Weight"].text.to_f * 4.54
# detail page
puts doc.elements["ItemLookupResponse/Items/Item/DetailPageURL"].text
# get cover pictures
def getCover(asin,url,size,local_folder)
filename = "#{local_folder}#{size}_#{asin}.jpg"
if File.exist?(filename)
puts "#{filename} exists."
else
puts "downloading #{url}... to #{filename}"
# download pict
pict = Net::HTTP.get_response(URI.parse(url))
File.open(filename, 'wb') {|f| f.write(pict.body)}
end
end
getCover(asin,doc.elements["ItemLookupResponse/Items/Item/SmallImage/URL"].text,'Small',book_covers)
getCover(asin,doc.elements["ItemLookupResponse/Items/Item/MediumImage/URL"].text,'Medium',book_covers)
getCover(asin,doc.elements["ItemLookupResponse/Items/Item/LargeImage/URL"].text,'Large',book_covers)
=end
=begin
1FNX6CR1RERFCW0804E10.0330460071563721TrueASINAll097669400XMedium097669400Xhttp://www.amazon.com/exec/obidos/redirect?tag=ws%26link_code=xm2%26camp=2025%26creative=165953%26path=http://www.amazon.com/gp/redirect.html%253fASIN=097669400X%2526tag=ws%2526lcode=xm2%2526cID=2025%2526ccmID=165953%2526location=/o/ASIN/097669400X%25253FSubscriptionId=1186KA3K523YWH49MV02656http://images.amazon.com/images/P/097669400X.01._SCTHUMBZZZ_.jpg7562http://images.amazon.com/images/P/097669400X.01._SCMZZZZZZZ_.jpg160133http://images.amazon.com/images/P/097669400X.01._SCLZZZZZZZ_.jpg500416http://images.amazon.com/images/P/097669400X.01._SCTHUMBZZZ_.jpg7562http://images.amazon.com/images/P/097669400X.01._SCMZZZZZZZ_.jpg160133http://images.amazon.com/images/P/097669400X.01._SCLZZZZZZZ_.jpg500416Dave ThomasDavid HanssonLeon BreedtMike ClarkThomas FuchsAndrea SchwarzPaperback97809766940071097669400X3495USD$34.951450105900187750Book2005-07-01Pragmatic BookshelfAgile Web Development with Rails : A Pragmatic Guide (The Facets of Ruby Series)2276USD$22.762276USD$22.763495USD$34.9525910Rails is a full-stack, open-source web framework that enables you to create full-featured, sophisticated web-based applications, but with a twist... A full Rails application probably has less total code than the XML you'd need to configure the same application in other frameworks. With this book you'll learn how to use <i>ActiveRecord</i> to connect business objects and database tables. No more painful object-relational mapping. Just create your business objects and let Rails do the rest. You'll learn how to use the <i>Action Pack</i> framework to route incoming requests and render pages using easy-to-write templates and components. See how to exploit the Rails service frameworks to send emails, implement web services, and create dynamic, user-centric web-pages using built-in Javascript and Ajax support. There are extensive chapters on testing, deployment, and scaling. You'll see how easy it is to install Rails using your web server of choice (such as Apache or lighttpd) or using its own included web server. You'll be writing applications that work with your favorite database (MySQL, Oracle, Postgres, and more) in no time at all. You'll create a complete online store application in the extended tutorial section, so you'll see how a full Rails application is developed---iteratively and rapidly. Rails strives to honor the Pragmatic Programmer's "DRY Principle" by avoiding the extra work of configuration files and code annotations. You can develop in real-time: make a change, and watch it work immediately. Forget XML. Everything in Rails, from templates to control flow to business logic, is written in Ruby, the language of choice for programmers who like to get the job done well (and leave work on time for a change). Rails is the framework of choice for the new generation of Web 2.0 developers. <em>Agile Web Development with Rails</em> is the book for that generation, written by Dave Thomas (Pragmatic Programmer and author of <em>Programming Ruby</em>) and David Heinemeier Hansson, who created Rails.
=end
=begin
1A8ACWG822D5K6X4HS5C0.0273139476776123TrueASINAll0976698746400XMediumAWS.InvalidParameterValue0976698746400X is not a valid value for ItemId. Please change this value and retry your request.
=end