-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_plot.rb
33 lines (27 loc) · 999 Bytes
/
update_plot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require "gphone_plotter_constants"
require "gphone_plotter_GnuplotScript"
require "gphone_plotter_FtpScript"
require "digest"
hash_file_path = "outputs/plot_hash.txt"
md5_new = Digest::MD5.hexdigest(File.read(CONSTANTS[:earthquake_file_path]))
gnuplot_script = GnuplotScript.new(CONSTANTS[:gnuplot_script_path], METERS)
ftp_script = FtpScript.new(CONSTANTS[:ftp_script_path], CONSTANTS[:www_ftp_user], CONSTANTS[:www_ftp_pass], [CONSTANTS[:plot_file_path]])
md5_f = File.new(hash_file_path,"a+")
md5_f.rewind
md5_s = md5_f.gets.chomp unless md5_f.eof?
if md5_s == md5_new
puts "No changes detected in '#{CONSTANTS[:earthquake_file_path]}'"
else
puts "Creating gnuplot script..."
gnuplot_script.create
puts "Running '#{CONSTANTS[:data_file_path]}' to gnuplot..."
gnuplot_script.execute
puts "\nCreating FTP script..."
ftp_script.create
puts "Running FTP script..."
ftp_script.execute
puts "\nWriting new MD5: #{md5_new}"
md5_f.rewind
md5_f.print md5_new
end
sleep 2