Created
June 11, 2014 12:01
-
-
Save CoffeeAndCode/4384f22c42cb95a37b16 to your computer and use it in GitHub Desktop.
Import to Day One app from idonethis csv export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cgi' | |
require 'csv' | |
require 'open3' | |
def readfile(file) | |
data = {} | |
CSV.foreach(file) do |row| | |
date = row[0] | |
text = row[1] | |
data[date] = [] unless data.has_key?(date) | |
data[date] << CGI.unescapeHTML(text) | |
end | |
data.each do |date, text_array| | |
text = text_array.map { |value| '* ' + value }.join("\n") | |
puts date | |
puts text | |
Open3.popen3('dayone', "-d=\"#{date}\"", 'new') do |stdin, stdout, stderr| | |
stdin.write(text) | |
stdin.close_write | |
puts stdout.read | |
end | |
puts "-------------------------------------------------------------" | |
end | |
end | |
readfile(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment