Created
June 8, 2014 19:44
-
-
Save campaul/5142232429aa63476032 to your computer and use it in GitHub Desktop.
Bucket CR2 files by date
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
from datetime import datetime | |
from os import walk | |
import sys | |
from wand.image import Image | |
def get_bucket(filename): | |
date = get_date(get_exif(filename)['DateTimeOriginal']) | |
return (str(date), filename) | |
def get_exif(filename): | |
exif = {} | |
with Image(filename=filename) as image: | |
exif.update((k[5:], v) for k, v in image.metadata.items() if k.startswith('exif:')) | |
return exif | |
def get_date(time_string): | |
return datetime.strptime(time_string, '%Y:%m:%d %H:%M:%S').date() | |
def get_raws(path): | |
for (path, dirs, files) in walk(path): | |
for f in files: | |
if f.split('.')[-1:] == ['CR2']: | |
yield path + f | |
def get_buckets(path): | |
for raw in get_raws(path): | |
yield get_bucket(raw) | |
# python raw_bucketer.py /path/to/raw/files | |
for bucket in get_buckets(sys.argv[1]): | |
print(bucket) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment