Skip to content

Instantly share code, notes, and snippets.

@warmlogic
Last active December 10, 2018 22:26
Show Gist options
  • Save warmlogic/9cdb28e09c1ec7691d426ced374985be to your computer and use it in GitHub Desktop.
Save warmlogic/9cdb28e09c1ec7691d426ced374985be to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# Script to migrate from Everyday to CloseUp (iOS apps for snapping daily photos)
# Instructions: https://closeup.wtf/everyday-import
# It seems that Everyday flips photos horizontally compared to CloseUp.
# CloseUp is like a mirror, but the photos from Everyday are the opposite (right on left).
# This script asks whether to flip the Everyday photos during export.
from __future__ import print_function # in case of python2
import sys
import sqlite3
import os
import shutil
# https://stackoverflow.com/a/5868543/2592858
try:
# in case of python2
input = raw_input
except NameError:
# for python3
pass
connection = sqlite3.connect('Everyday2.sqlite')
# https://stackoverflow.com/a/839419/3943258
timelineCount = connection.execute('SELECT COUNT(*) FROM ZTIMELINE').fetchone()[0]
timelinePrimaryKey = None
timelineFolderName = None
if timelineCount == 1:
timelinePrimaryKey = connection.execute('SELECT Z_PK FROM ZTIMELINE').fetchone()[0]
timelineFolderName = connection.execute('SELECT ZIDENTIFIER FROM ZTIMELINE').fetchone()[0]
else:
print('Please choose a timeline to export:')
for row in connection.execute('SELECT Z_PK,ZLABEL FROM ZTIMELINE'):
query = 'SELECT COUNT(*) FROM ZPHOTO WHERE ZTIMELINE = {r0}'.format(r0=row[0])
tl_row = '{r0}: {r1} ({ce} photos)'.format(
r0=row[0], r1=row[1],
ce=connection.execute(query).fetchone()[0],
)
print(tl_row)
get_input = input()
for row in connection.execute('SELECT Z_PK,ZIDENTIFIER FROM ZTIMELINE'):
if str(row[0]) == get_input:
timelinePrimaryKey = row[0]
timelineFolderName = row[1]
break
if timelinePrimaryKey is None:
print('Timeline {tl} not found, please try again'.format(tl=get_input))
sys.exit()
# print('Proceeding with {} and {}'.format(timelinePrimaryKey, timelineFolderName))
if os.path.exists('ExportedPhotos'):
shutil.rmtree('ExportedPhotos')
os.makedirs('ExportedPhotos')
flip_horizontal = None
print("CloseUp's photos are shown like you're looking in a mirror, but Everyday saves them flipped horizontally.")
print("Should I flip your photos horizontally to match CloseUp's photos? (y/n)")
while flip_horizontal is None:
get_input = input()
if get_input.lower() == 'y':
flip_horizontal = True
elif get_input.lower() == 'n':
flip_horizontal = False
else:
print('Please answer y or n')
count = 0
query = 'SELECT ZCREATED,ZIDENTIFIER FROM ZPHOTO WHERE ZTIMELINE = {}'.format(timelinePrimaryKey)
for row in connection.execute(query):
count = count + 1
input_file = 'photos/{tf}/{rn}.jpg'.format(tf=timelineFolderName, rn=row[1])
output_file = 'ExportedPhotos/{fn:.6f}.jpg'.format(fn=row[0] + 978307200.000000)
shutil.copyfile(input_file, output_file)
if flip_horizontal:
os.system('sips -f horizontal {of}'.format(of=output_file))
print("\nDONE!\nExported {co} photos to 'ExportedPhotos', copy those into your Close-up directory in Dropbox/Apps to sync them.".format(co=count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment