Skip to content

Instantly share code, notes, and snippets.

@philipbl
Created August 15, 2012 22:58
Show Gist options
  • Save philipbl/3364458 to your computer and use it in GitHub Desktop.
Save philipbl/3364458 to your computer and use it in GitHub Desktop.
Finds pictures paths (surrounded with [ ]) and adds a new entry in Day One with the same date and time
#!/bin/python
import os
directory = '/Users/philiplundrigan/Dropbox/Journal_dayone/entries'
src_directory = '/Users/philiplundrigan/Documents/Journal Backups/Journal Backup (2012)/Journal Backup (2012)'.replace(' ', '\ ').replace('(', '\(').replace(')', '\)')
def getDate(file):
for line in open(directory + '/' + file):
if line.find('<date>') != -1:
return line[7:-8]
def getPictureNames(file):
names = []
for line in open(directory + '/' + file):
if line.find('[') != -1:
names.append(line[1:-2])
return names
def createNewEntry(file, pictures):
for picture in pictures:
command = "dayone -d={0} -p={1} new".format(getDate(file), src_directory + '/' + picture.replace('%20', ' ').replace(' ', '\ ').replace('%3A', '\:')).replace('\'', '\\\'')
print command
os.system(command)
print '\n\n'
def containsPicture(file):
names = getPictureNames(file)
createNewEntry(file, names)
for file in os.listdir(directory):
for line in open(directory + '/' + file):
if line.find('[') != -1:
containsPicture(file)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment