Merge branch 'master' of /home/git/Autotest.mk
[autotest_mk.git] / plot_batch.rb
1 #!/usr/local/bin/ruby
2 # -*- coding: utf-8 -*-
3
4 # Rプログラムのパス
5 rpath = "/usr/local/bin/R"
6
7 # 作業用ディレクトリのトップ
8 workdir = File.expand_path("~/amazonrank")
9
10 # Rのグラフ出力プログラム
11 plotfile = workdir.dup << "/plot.R"
12
13 # ASINリストファイル
14 isbnfile = workdir.dup << "/ISBN.txt"
15
16 # データCSVファイルを格納するディレクトリ
17 csvdir = workdir.dup
18
19 # HTMLファイルおよびデータCSVファイルを格納するディレクトリ
20 htmldir = workdir.dup
21
22 # プロット時のエラー記録ファイル
23 ploterrfile = workdir.dup << "/error_plot.log"
24
25 open(isbnfile, "r") { |lines|
26   begin
27     while isbn = lines.gets
28       isbn = isbn.chomp
29       cmd = rpath.dup << " --vanilla --slave --args " << isbn.dup << " " << csvdir.dup << " " << htmldir.dup << " <" << plotfile.dup << " 2>>" << ploterrfile.dup
30       system(cmd)
31       raise "ASIN:" << isbn.dup << " コマンド実行エラー" if $? != 0
32     end
33   rescue => exc
34     STDERR.puts exc
35     errfile = File.expand_path(ploterrfile.dup)
36     open(errfile, "a") { |f|
37       f.print "ASIN: ", isbn, "\n"
38       f.print "日時: ", Time.now.strftime("%Y/%m/%d %H:%M:%S"), "\n"
39       f.print "\n"
40     }
41     retry
42   end
43 }