Last active
January 2, 2016 00:38
-
-
Save jsonbecker/8224317 to your computer and use it in GitHub Desktop.
A few versions of getting date data from photos.
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
import sys | |
import os, shutil, time | |
import subprocess | |
import os.path | |
import exifread | |
from datetime import datetime | |
def photoDateSIPS(f): | |
"Return the date/time on which the given photo was taken." | |
cDate = subprocess.check_output(['sips', '-g', 'creation', f]) | |
cDate = cDate.split('\n')[1].lstrip().split(': ')[1] | |
return datetime.strptime(cDate, "%Y:%m:%d %H:%M:%S") | |
def photoDateMod(f): | |
"Return the date/time the photo was last modified." | |
cDate = time.ctime(os.path.getmtime(f)) | |
return datetime.strptime(cDate, "%a %b %d %H:%M:%S %Y") | |
def photoDateEXIF(f): | |
"Return date time based on the EXIF data DateTimeOriginal" | |
f = open(f, 'rb') | |
tags = exifread.process_file(f) | |
try: | |
cDate = str(tags['EXIF DateTimeOriginal']) | |
except KeyError: | |
try: | |
cDate = str(tags['Image DateTime']) | |
except: | |
return Exception | |
f.close() | |
try: | |
output = datetime.strptime(cDate, "%Y:%m:%d %H:%M:%S") | |
except: | |
return Exception | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment