Last active
December 12, 2015 07:18
-
-
Save apiarian/4735208 to your computer and use it in GitHub Desktop.
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
# generate_gif.py | |
# Aleksandr Pasechnik | |
# | |
# Creates an animated gif out of the photos found in a Day One journal | |
# based the first line of the entry ('Daily self portrai' in my case). | |
# Animated gifs are generated using imagemagick | |
import os | |
import plistlib | |
import subprocess | |
base_dir = '~/Library/Mobile Documents/5U8NS4GX82~com~dayoneapp~dayone/Documents/Journal_dayone/' | |
base_dir = os.path.expanduser(base_dir) | |
entries_dir = os.path.join(base_dir,'entries') | |
photos_dir = os.path.join(base_dir,'photos') | |
files = os.listdir(entries_dir) | |
files[:] = [file for file in files if file.endswith('.doentry')] | |
entries = [] | |
for file in files: | |
filename = os.path.join(entries_dir,file) | |
entries.append(plistlib.readPlist(filename)) | |
entries = sorted(entries, key=lambda entry:entry['Creation Date']) | |
# this line filters the entries for the specific ones that I'm interested in | |
entries[:] = [e for e in entries if e['Entry Text'].splitlines()[0].startswith('Daily self portrait')] | |
photo_list = [] | |
for entry in entries: | |
photo = os.path.join(photos_dir,entry['UUID']+'.jpg') | |
print 'looking for photo',photo | |
if os.path.exists(photo): | |
print 'photo exists:',photo | |
photo_list.append(photo) | |
print '' | |
for photo in photo_list: | |
print photo | |
command = [ | |
'/usr/local/bin/convert', | |
'-loop', '0', | |
'-delay', '25' | |
] | |
command.extend(photo_list) | |
command.append(os.path.expanduser('~/Desktop/dsp.gif')) | |
p = subprocess.Popen(command) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment