Last active
August 29, 2015 14:06
-
-
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.
This file contains 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
#!/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 |
This file contains 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
envoy==0.0.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment