From b78c53441dc62fd2db50d288e38f59731aa04cab Mon Sep 17 00:00:00 2001 From: rrr-marble Date: Sun, 19 Dec 2021 04:13:36 +0300 Subject: [PATCH] add: skip adding images with invalid exif to db --- util/import_photos.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/util/import_photos.py b/util/import_photos.py index b165a1a..a14e7f0 100644 --- a/util/import_photos.py +++ b/util/import_photos.py @@ -41,16 +41,20 @@ def process_pictures(source: str, dest_shrunk: str, dest_original: str): # Q: do we strip exif from originals? move(path.join(root, filename), dest_original) - # return the freshly processed picture info - yield { - "ResizedImage": path.join(dest_shrunk, filename), - "OriginalImage": path.join(dest_original, filename), - "DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it? - "GPSLatitude": exif["GPSLatitude"], - "GPSLatitudeRef": exif["GPSLatitudeRef"], - "GPSLongitude": exif["GPSLongitude"], - "GPSLongitudeRef": exif["GPSLongitudeRef"], - } + try: + # return the freshly processed picture info + yield { + "ResizedImage": path.join(dest_shrunk, filename), + "OriginalImage": path.join(dest_original, filename), + "DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it? + "GPSLatitude": exif["GPSLatitude"], + "GPSLatitudeRef": exif["GPSLatitudeRef"], + "GPSLongitude": exif["GPSLongitude"], + "GPSLongitudeRef": exif["GPSLongitudeRef"], + } + except KeyError as e: + print(f"Image '{filename}' has no valid exif") + continue def update_database(pic_info: dict, db_location: str):