Skip to content

Instantly share code, notes, and snippets.

@tuaplicacionpropia
Created July 15, 2018 19:52
Show Gist options
  • Save tuaplicacionpropia/db4fa7f5026a1d2eee37ef4ed31c0eb9 to your computer and use it in GitHub Desktop.
Save tuaplicacionpropia/db4fa7f5026a1d2eee37ef4ed31c0eb9 to your computer and use it in GitHub Desktop.
Get Date of Photo/Image
#!/usr/bin/env python2.7
import sys
import locale
from PIL import Image
from PIL.ExifTags import TAGS
from datetime import datetime
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
#'DateTime': u'2017:12:21 10:52:44'
def get_fecha (fn):
result = None
data = get_exif(fn)
key = 'DateTime'
if key in data:
dateTxt = data[key]
datetime_object = datetime.strptime(dateTxt, '%Y:%m:%d %H:%M:%S')
locale.setlocale(locale.LC_ALL, 'es_ES.UTF-8')
result = datetime_object.strftime("%A %-d de %B de %Y")
return result
print get_fecha(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment