From d743ede95dd8dcd02b9c3bac386e456241532d68 Mon Sep 17 00:00:00 2001 From: Flo Greistorfer Date: Mon, 23 Sep 2024 12:37:52 +0200 Subject: [PATCH] added regular expression to datetime conversion --- modules/generate_html.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/generate_html.py b/modules/generate_html.py index 50c26e0..911b438 100644 --- a/modules/generate_html.py +++ b/modules/generate_html.py @@ -1,4 +1,5 @@ import os +import re import urllib.parse import fnmatch import json @@ -115,7 +116,11 @@ def get_image_info(item: str, folder: str) -> Dict[str, Any]: if newtuple: content = newtuple if tag in ["DateTime", "DateTimeOriginal", "DateTimeDigitized"]: - content = datetime.strptime(content, "%Y:%m:%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S") + epr = r'\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}' + if re.match(epr, content): + content = datetime.strptime(content, "%Y:%m:%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S") + else: + content = None exifdata[tag] = content if "Orientation" in exifdata and exifdata["Orientation"] in [6, 8]: logger.info("image is rotated", extra={"file": file})