Merge branch 'master' of /home/git/amazonrank
[autotest_mk.git] / bookrank_batch.rb
1 #!/usr/local/bin/ruby
2 # -*- coding: utf-8 -*-
3 require 'amazon/aws/search'
4 include Amazon::AWS
5
6 workdir = File.expand_path("~/amazonrank")
7 isbnfile = File.expand_path(workdir.dup << "/ISBN.txt")
8
9 open(isbnfile, "r") { |lines|
10   while isbn = lines.gets
11     isbn = isbn.chomp
12     csvfile = File.expand_path(workdir.dup << "/" << isbn.dup <<  ".csv")
13     il = ItemLookup.new( 'ASIN', { 'ItemId' => isbn } )
14     request  = Search::Request.new
15     time  = Time.now
16     req = request.search il
17     open(csvfile, "a") { |f|
18       f.print isbn, ",", time.strftime("%Y/%m/%d %H:%M:%S"), ",", req.item_lookup_response.items.item.sales_rank, "\n"
19     }
20     sleep 0.5
21   end
22 }