From f8383567fe0180830a18af2675d99fa4ce63a85b Mon Sep 17 00:00:00 2001 From: DasMoorhuhn Date: Thu, 21 Dec 2023 11:27:29 +0100 Subject: [PATCH] changed to dict --- src/exif_data.py | 16 ++++++++-------- src/file_handler.py | 1 - src/meta_data_handler.py | 21 ++++++++++++++++++++- src/process.py | 2 ++ tests/test_exif_data.py | 20 +++++++++++++------- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/exif_data.py b/src/exif_data.py index be26a64..471fac7 100644 --- a/src/exif_data.py +++ b/src/exif_data.py @@ -1,10 +1,10 @@ class ExifData: """This is for an object that stores the data of a picture""" - def __init__(self, image_path:str, image_name:str, day:int, month:int, year:int, time:str, make:str) -> None: - self.path:str = image_path - self.name:str = image_name - self.day:int = int(day) - self.month:int = int(month) - self.year = int(year) - self.time = str(time) - self.make = str(make) + def __init__(self, data:dict) -> None: + self.path:str = data['image_path'] + self.name:str = data['image_name'] + self.day:int = data['day'] + self.month:int = data['month'] + self.year = data['year'] + self.time = data['time'] + self.make = data['make'] diff --git a/src/file_handler.py b/src/file_handler.py index beba1a4..832c7b2 100644 --- a/src/file_handler.py +++ b/src/file_handler.py @@ -12,7 +12,6 @@ from src.exif_data import ExifData def sort_pictures(images:list, dst:str, logger:logging.Logger): image_total = len(images) image_counter = 0 - logging_infos = [] progress_bar = ProgressBar( maxval=image_total, term_width=70 diff --git a/src/meta_data_handler.py b/src/meta_data_handler.py index 72fb1ee..14c2252 100644 --- a/src/meta_data_handler.py +++ b/src/meta_data_handler.py @@ -19,9 +19,17 @@ def is_file_video(path:str): else: return False +def is_file_picture(path:str): + mime = magic.Magic(mime=True) + file = mime.from_file(path) + if file.find('picture') != -1: return True + else: return False + + def get_image_meta_data(image_path): image_extension = str(image_path).split("/")[-1].split(".") # TODO: Sort out videos + if is_file_video(path=image_path): return False img = Image.open(f"{image_path}") values = [] for tag, text in img.getexif().items(): @@ -36,6 +44,7 @@ def filter_date_and_make(meta_tags:list, image_path): month = None year = None time = None + print(meta_tags) make = str(meta_tags[1]).split("|")[1] image_name = str(image_path).split("/")[-1] @@ -46,7 +55,17 @@ def filter_date_and_make(meta_tags:list, image_path): month = int(_date[1]) year = int(_date[0]) - return ExifData(image_path=image_path, image_name=image_name, day=day, month=month, year=year, time=time, make=make) + exif_data_dict = { + "day": day, + "month": month, + "year": year, + "make": make, + "time": time, + "image_path": image_path, + "image_name": image_name + } + + return ExifData(exif_data_dict) def filter_data(value): diff --git a/src/process.py b/src/process.py index 5165a82..fdba5f9 100644 --- a/src/process.py +++ b/src/process.py @@ -14,8 +14,10 @@ def start_process(logger): if len(files) > 0: exif_data = get_meta_data(images=files) sort_pictures(images=exif_data, dst=config.dst, logger=logger) + return True else: print("No images found") + return False except Exception as err: print(err) logger.error(err) diff --git a/tests/test_exif_data.py b/tests/test_exif_data.py index 52593b1..4810321 100644 --- a/tests/test_exif_data.py +++ b/tests/test_exif_data.py @@ -4,12 +4,18 @@ import unittest class TestExifData(unittest.TestCase): def test_exif_data(self): - exif_data = ExifData(image_path="/path/to/image", - image_name="Image.jpeg", - make="CAMERA", - month=12, - day=12, - year=2023, - time="10:10:10") + exif_data_dict = { + "day": 2, + "month": 2, + "year": 2222, + "make": "CAMERA", + "time": "10:10:10", + "image_path": "/path/to/image", + "image_name": "Image.jpeg" + } + exif_data = ExifData(exif_data_dict) assert exif_data.make == "CAMERA" + assert exif_data.year == 2222 + assert exif_data.time == "10:10:10" +