rrichards
5/2/2014 - 9:14 AM

macjournal_import.rb

require "open3"

def readfile(file)

	f = File.open(file)
	lines = f.readlines("\n\n\n\n")
	lines.each do |line|
		fields = line.scan(/\s+Date:\s([^\n]+)$\s+Topic:\s([^\n]+)\n(.*)/m)

		date = fields[0][0].strip
		topic = fields[0][1].strip
		text = topic + "\n" + fields[0][2].strip

		puts date
		puts text
		puts "-------------------------------------------------------------"

		Open3.popen3("/Applications/Day One.app/Contents/MacOS/dayone", "-d=\"#{date}\"", "new") do |stdin, stdout, stderr|
			stdin.write(text)
			stdin.close_write
			puts stdout.read
		end

		puts "-------------------------------------------------------------"
	end
end

readfile(ARGV[0])