Skip to content

Instantly share code, notes, and snippets.

@Kobold
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kobold/cf497a7e2b8ab3ac89d1 to your computer and use it in GitHub Desktop.
Save Kobold/cf497a7e2b8ab3ac89d1 to your computer and use it in GitHub Desktop.
Import an ohlife.com export text file to the mac app Day One.
#!/usr/bin/env python
"""
Run me like: python ohlife_to_dayone.py /Users/Kobold/Downloads/ohlife_20140925.txt
"""
import envoy
import re
import sys
def entries(filename):
timestamp = None
entry = ''
with file(filename) as f:
for line in f.readlines():
if re.match('\d{4}-\d{2}-\d{2}', line): # it's a timestamp line
if timestamp:
yield timestamp, entry.strip()
timestamp = line.strip()
entry = ''
else: # an entry line
entry += line
yield timestamp, entry.strip()
if __name__ == '__main__':
_, ohlife_file = sys.argv
for timestamp, entry in entries(ohlife_file):
r = envoy.run('dayone -d="{}" new'.format(timestamp), data=entry)
print r.std_out.strip()
print ' exited with', r.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment