Skip to content

Instantly share code, notes, and snippets.

@galtenberg
Created August 6, 2014 22:58
Show Gist options
  • Save galtenberg/c358f9d074d759b67c6c to your computer and use it in GitHub Desktop.
Save galtenberg/c358f9d074d759b67c6c to your computer and use it in GitHub Desktop.
Creates Lkmake/Simplenote import-compatible json given plaintext file of notes separated by two blank lines
# Creates Lkmake/Simplenote import-compatible json given plaintext file of notes separated by two blank lines
# Author: Christopher Galtenberg
# License: Use it for good, however you like
# Input file:
# example note 1
#
# example note 2
# Output file:
# [{"createdate":"Aug 01 2014 00:00:01","modifydate":"Aug 01 2014 00:00:00","content":"example 1"},{"createdate":"Aug 01 2014 00:00:02","modifydate":"Aug 01 2014 00:00:00","content":"example 2"}]
# Note: Lkmake requires non-conflicting createdate. Hence a time counter that increments createdate by 1 second for each note.
require 'date'
require 'json'
INPUT_FILE = "/Users/yourlogin/notes.txt"
OUTPUT_FILE = "/Users/yourlogin/notes.json"
START_DATE = Date.today.to_time
input = File.read INPUT_FILE
elements = input.split "\n\n"
output = File.open OUTPUT_FILE, 'w'
startstrf = START_DATE.strftime("%b %d %Y %H:%M:%S")
counter = START_DATE.to_i
outhash = elements.map do |elem|
counter = counter + 1
{ "createdate" => Time.at(counter).strftime("%b %d %Y %H:%M:%S"), "modifydate" => startstrf, "content" => elem }
end
output.write outhash.to_json
output.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment