Fix two issues in new-photo-post.py
- Strip typographic quotes from input to slugify() - Fall back on a floating timestamp if no timezone is given
This commit is contained in:
parent
039efa3c23
commit
1e851f7061
1 changed files with 7 additions and 3 deletions
|
@ -17,7 +17,7 @@ from PIL.ExifTags import TAGS
|
|||
PHOTOS_CONTENT_DIR = 'content/photos'
|
||||
|
||||
def slugify(s):
|
||||
return re.sub(r'\s+', '-', s.strip().lower())
|
||||
return re.sub(r'[‘’“”]', '', re.sub(r'\s+', '-', s.strip().lower()))
|
||||
|
||||
def parse_args(argv, *a, **kw):
|
||||
parser = argparse.ArgumentParser(*a, **kw)
|
||||
|
@ -42,8 +42,12 @@ def main(argv):
|
|||
raw_exif = image._getexif()
|
||||
friendly_exif = {TAGS[k]: v for k, v in raw_exif.items() if k in TAGS}
|
||||
|
||||
date_string = f'{friendly_exif["DateTime"]} {friendly_exif["OffsetTime"]}'
|
||||
exif_date = datetime.datetime.strptime(date_string, '%Y:%m:%d %H:%M:%S %z')
|
||||
try:
|
||||
date_string = f'{friendly_exif["DateTime"]} {friendly_exif["OffsetTime"]}'
|
||||
exif_date = datetime.datetime.strptime(date_string, '%Y:%m:%d %H:%M:%S %z')
|
||||
except KeyError:
|
||||
exif_date = datetime.datetime.strptime(friendly_exif["DateTime"], '%Y:%m:%d %H:%M:%S')
|
||||
|
||||
print(f'{photo} -> {exif_date.isoformat()}')
|
||||
|
||||
if not earliest_exif_date or exif_date < earliest_exif_date:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue