Skip to content

Instantly share code, notes, and snippets.

@CoffeeAndCode
Created June 11, 2014 12:01
Show Gist options
  • Save CoffeeAndCode/4384f22c42cb95a37b16 to your computer and use it in GitHub Desktop.
Save CoffeeAndCode/4384f22c42cb95a37b16 to your computer and use it in GitHub Desktop.
Import to Day One app from idonethis csv export
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