Closed gangelop closed 3 years ago
This would fix the bug but there's got to be a more elegant way to write it.
def get_exif(filename):
exif_data = {}
exif = Image.open(filename)._getexif()
if exif is not None:
for (tag, value) in exif.items():
decoded = TAGS.get(tag, tag)
exif_data[decoded] = value
if 'DateTime' in exif_data:
datetime = exif_data['DateTime']
else:
datetime = strftime("%Y:%m:%d %H:%M:00", gmtime(os.path.getmtime(filename)))
else:
datetime = strftime("%Y:%m:%d %H:%M:00", gmtime(os.path.getmtime(filename)))
return datetime
of course there was a more elegant solution.
We first attempt to populate the exif_data
and then if
it's populated we use it else
we use getmtime
so it's always one or the other. No error here because exif_data
is already initialized as {}
.
def get_exif(filename):
exif_data = {}
exif = Image.open(filename)._getexif()
if exif is not None:
for (tag, value) in exif.items():
decoded = TAGS.get(tag, tag)
exif_data[decoded] = value
if 'DateTime' in exif_data:
datetime = exif_data['DateTime']
else:
datetime = strftime("%Y:%m:%d %H:%M:00", gmtime(os.path.getmtime(filename)))
return datetime
version 1.0.1 On running
prosopopee autogen -d $somedir
it fails with:This is the offending function. Clearly there is one case where datetime does not get set.
I can't look into it further right now. I might later.