-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmomento2dayone.rb
executable file
·44 lines (33 loc) · 1.13 KB
/
momento2dayone.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
#!/usr/bin/env ruby
require File.dirname(__FILE__) + "/date_format"
require File.dirname(__FILE__) + "/day"
require File.dirname(__FILE__) + "/entry"
require File.dirname(__FILE__) + "/input"
include Input
@days = []
@current_entry = nil
@current_day = nil
ARGF.each_line do |line|
line = process_line(line)
if line =~ /^(#{ Day::DAYS }) (\d+) (#{ Day::MONTHS }) (#{ Day::YEARS })\r\n$/
@current_entry = Entry.new(nil, nil, [])
@current_day = Day.new(Date.parse("#{$3} #{$2}, #{$4}"), [ @current_entry ])
@days << @current_day
# skip the next two lines...
3.times { line = read_and_process_line(line) }
@current_entry.process_time_line line
elsif line =~ /^#{ TIME_SEPARATOR }$/
# skip the next line...
2.times { line = read_and_process_line(line) }
@current_entry = Entry.new(nil, nil, [])
@current_day.entries << @current_entry
@current_entry.process_time_line line
elsif @current_entry
@current_entry.lines << line
end
end
@days.each do |day|
day.entries.each do |entry|
system "echo \"#{entry.lines.join}\" | dayone -d=\"#{day.date.to_s} #{entry.time}\" new"
end
end