-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_ecam_capturetimes.rb
51 lines (42 loc) · 1.3 KB
/
extract_ecam_capturetimes.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "rexml/document"
require "json"
require "time"
require "active_support"
require "active_support/core_ext"
capture_times = []
dir = ARGV[0].dup
time_diff = 0
print_seconds = true
show_time_zone = false
path_to_tm_json = ARGV[1]
time_zone = "Eastern Time (US & Canada)"
while !ARGV.empty?
arg = ARGV.shift
if arg == "-subsample-input"
subsample_input = ARGV.shift.to_i
elsif arg == "--print-seconds"
print_seconds = true
elsif arg == "-capture-time-diff"
time_diff = ARGV.shift.to_i
elsif arg == "-time-zone"
time_zone = ARGV.shift
elsif arg == "--show-time-zone"
show_time_zone = true
end
end
Time.zone = time_zone
dir.chop! if dir[-1,1] == "/" || dir[-1,1] == "\\"
path = File.expand_path('**/*.[jJpP][pPnN][gG]', dir)
files = Dir.glob(path).sort
files.each do |img_path|
file = File.basename(img_path)
date = file.split("_")[0].to_i
date += time_diff
extra = print_seconds ? ":%S" : ""
time_zone_str = show_time_zone ? Time.zone.tzinfo.strftime(" %Z") : ""
capture_times << Time.zone.at(date).to_datetime.strftime("%Y-%m-%d %H:%M:%S") + time_zone_str
end
json = open(path_to_tm_json) {|fh| JSON.load(fh)}
json["capture-times"] = capture_times
open(path_to_tm_json, "w") {|fh| fh.puts(JSON.generate(json))}
STDERR.puts "Successfully wrote capture times to #{path_to_tm_json}"