Created
November 24, 2015 17:42
-
-
Save elipapa/7d596ceeff02a682bc43 to your computer and use it in GitHub Desktop.
converting journey android app entries to dayone entries using the the dayone-cli limited input options
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 python3 | |
## converting journey android app entries to dayone entries using the the dayone-cli limited input options | |
# first download all single posts zip files and place them in the folder of the script. Then run | |
# unzip '*.zip' | |
# where quotes are important! | |
# | |
# Then run this script in the folder | |
import json | |
import os, glob | |
from subprocess import Popen, PIPE, STDOUT | |
import datetime | |
for f in glob.glob('*.json'): | |
with open(f,'r') as fh: | |
j = json.load(fh) | |
text = j['text'] | |
date = j['date_journal'] | |
dateobj = datetime.datetime.fromtimestamp(date/1000) | |
if j['photos']: | |
photo = j['photos'][0] | |
cmd = ['dayone', '-p=%s' % photo, '-d="%s"' % dateobj.strftime('%m/%d/%Y %H:%M'), 'new'] | |
else: | |
cmd = ['dayone','-d="%s"' % dateobj.strftime('%m/%d/%Y %H:%M'), 'new'] | |
print(' '.join(cmd)) | |
p = Popen(cmd, stdin=PIPE) | |
stdout_data = p.communicate(input=str.encode(text))[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment