Merge branch 'master' of /home/git/amazonrank
[autotest_mk.git] / bookrank.rb
1 # -*- coding: utf-8 -*-
2 require 'amazon/aws/search'
3 include Amazon::AWS
4 workdir = File.expand_path("~/amazonrank")
5
6 begin
7   il = ItemLookup.new( 'ASIN', { 'ItemId' => ARGV[0] } )
8   request  = Search::Request.new
9   time  = Time.now.strftime("%Y/%m/%d %H:%M:%S")
10   req = request.search il
11   rank = req.item_lookup_response.items.item.sales_rank
12   raise "ランキングを取得できませんでした。原因不明" if req.nil?
13   csvfile = File.expand_path(workdir.dup << "/" << ARGV[0].dup <<  ".csv")
14   open(csvfile, "a") { |f|
15     f.print ARGV[0], ",", time, ",", req, "\n"
16   }
17 rescue => exc
18   STDERR.puts exc
19   errfile = File.expand_path(workdir.dup << "/error.log")
20   open(errfile, "a") { |f|
21     f.print "エラー: ", exc, "\n"
22     f.print "ASBN: ", ARGV[0], "\n"
23     f.print "日時: ", time, "\n"
24     f.print "\n"
25   }
26 end