From 4fe97384e849bb135af26969bf6c051e0885705c Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 25 Oct 2021 08:50:39 +0300 Subject: [PATCH] Change date format to use dots --- README.md | 6 ++++++ image_classifier/image_classifier.py | 19 ++++++++++--------- setup.cfg | 2 +- setup.py | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e18225e..14f61e3 100755 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ == image_classifier + +Classifies images by their EXIF date (e.g. /path/YYYY.MM.DD/image.jpg). + += Install + +python3 setup.py install \ No newline at end of file diff --git a/image_classifier/image_classifier.py b/image_classifier/image_classifier.py index 2c16aba..ad0284a 100755 --- a/image_classifier/image_classifier.py +++ b/image_classifier/image_classifier.py @@ -90,17 +90,18 @@ class image_classifier: if 'Exif.Photo.DateTimeOriginal' in self.metadata.exif_keys: original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value self._log.debug(f"File creation time: {original_date} (type: {type(original_date)})") - new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename) - if not new_path: + folder = os.path.join(dirname, original_date.strftime('%Y.%m.%d'), filename) + if not folder: match = re.search(r'(?P20[0-9]{2})[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P[0-3]?[0-9])', filename) if match: - new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) - if not new_path: - match = re.search(r'(?P[0-3]?[0-9])[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P20[0-9]{2})', filename) - if match: - new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) - if not new_path: - new_path = os.path.join(dirname, 'unknown-time', filename) + folder = f"{match.group('year')}.{match.group('month')}.{match.group('day')}" + else: + match = re.search(r'(?P[0-3]?[0-9])[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P20[0-9]{2})', filename) + if match: + folder = f"{match.group('year')}.{match.group('month')}.{match.group('day')}" + else: + folder = 'unknown-time' + new_path = os.path.join(dirname, folder, filename) os.makedirs(os.path.dirname(new_path), exist_ok=True) if self.no_move == False: self._log.info(f"Moving file '{file}' to '{new_path}'...") diff --git a/setup.cfg b/setup.cfg index 7939e60..19e8fd3 100755 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = image_classifier -version = 0.0.4 +version = 0.0.5 [options] packages = image_classifier diff --git a/setup.py b/setup.py index cda86e1..5019b90 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ if os.access(requirements_file, os.R_OK): setuptools.setup( scripts=['image_classifier/image_classifier.py'], author="Antonio J. Delgado", - version='0.0.4', + version='0.0.5', name='image_classifier', author_email="antoniodelgado@susurrando.com", url="",