Created
November 21, 2010 12:50
-
-
Save markandey/708717 to your computer and use it in GitHub Desktop.
python script which displays a command suggestion to move your images in directories based on their EXIF data (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
#!/usr/bin/env python | |
from PIL import Image | |
from PIL.ExifTags import TAGS | |
import sys | |
import datetime | |
from sys import exit | |
def get_exif(fn): | |
ret = {} | |
i = Image.open(fn) | |
info = i._getexif() | |
for tag, value in info.items(): | |
decoded = TAGS.get(tag, tag) | |
ret[decoded] = value | |
return ret | |
if len(sys.argv)<2: | |
print 'filename is missing'; | |
print 'Usage:',sys.argv[0],'<filename>','<option>' ; | |
print 'd for date, m for month and y for year' ; | |
raise SystemExit; | |
filename = sys.argv[1] | |
option='d'; | |
if len(sys.argv)<3: | |
option='d'; | |
else: | |
option=sys.argv[2] | |
info=get_exif(filename); | |
try: | |
for attr in info: | |
if attr=='DateTimeOriginal': | |
d=datetime.datetime.strptime(info[attr], "%Y:%m:%d %H:%M:%S"); | |
if option=='d': | |
print 'cmd',filename, d.strftime("%d:%m:%Y") ; | |
elif option=='m': | |
print 'cmd',filename, d.strftime("%m:%Y") ; | |
elif option=='m': | |
print 'cmd',filename, d.strftime("%Y") ; | |
else: | |
print 'wrong option!'; | |
break; | |
except: | |
print 'error'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment