changed to dict
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
class ExifData:
|
class ExifData:
|
||||||
"""This is for an object that stores the data of a picture"""
|
"""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:
|
def __init__(self, data:dict) -> None:
|
||||||
self.path:str = image_path
|
self.path:str = data['image_path']
|
||||||
self.name:str = image_name
|
self.name:str = data['image_name']
|
||||||
self.day:int = int(day)
|
self.day:int = data['day']
|
||||||
self.month:int = int(month)
|
self.month:int = data['month']
|
||||||
self.year = int(year)
|
self.year = data['year']
|
||||||
self.time = str(time)
|
self.time = data['time']
|
||||||
self.make = str(make)
|
self.make = data['make']
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from src.exif_data import ExifData
|
|||||||
def sort_pictures(images:list, dst:str, logger:logging.Logger):
|
def sort_pictures(images:list, dst:str, logger:logging.Logger):
|
||||||
image_total = len(images)
|
image_total = len(images)
|
||||||
image_counter = 0
|
image_counter = 0
|
||||||
logging_infos = []
|
|
||||||
progress_bar = ProgressBar(
|
progress_bar = ProgressBar(
|
||||||
maxval=image_total,
|
maxval=image_total,
|
||||||
term_width=70
|
term_width=70
|
||||||
|
|||||||
@@ -19,9 +19,17 @@ def is_file_video(path:str):
|
|||||||
else: return False
|
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):
|
def get_image_meta_data(image_path):
|
||||||
image_extension = str(image_path).split("/")[-1].split(".")
|
image_extension = str(image_path).split("/")[-1].split(".")
|
||||||
# TODO: Sort out videos
|
# TODO: Sort out videos
|
||||||
|
if is_file_video(path=image_path): return False
|
||||||
img = Image.open(f"{image_path}")
|
img = Image.open(f"{image_path}")
|
||||||
values = []
|
values = []
|
||||||
for tag, text in img.getexif().items():
|
for tag, text in img.getexif().items():
|
||||||
@@ -36,6 +44,7 @@ def filter_date_and_make(meta_tags:list, image_path):
|
|||||||
month = None
|
month = None
|
||||||
year = None
|
year = None
|
||||||
time = None
|
time = None
|
||||||
|
print(meta_tags)
|
||||||
make = str(meta_tags[1]).split("|")[1]
|
make = str(meta_tags[1]).split("|")[1]
|
||||||
image_name = str(image_path).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])
|
month = int(_date[1])
|
||||||
year = int(_date[0])
|
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):
|
def filter_data(value):
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ def start_process(logger):
|
|||||||
if len(files) > 0:
|
if len(files) > 0:
|
||||||
exif_data = get_meta_data(images=files)
|
exif_data = get_meta_data(images=files)
|
||||||
sort_pictures(images=exif_data, dst=config.dst, logger=logger)
|
sort_pictures(images=exif_data, dst=config.dst, logger=logger)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
print("No images found")
|
print("No images found")
|
||||||
|
return False
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(err)
|
print(err)
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
|||||||
@@ -4,12 +4,18 @@ import unittest
|
|||||||
|
|
||||||
class TestExifData(unittest.TestCase):
|
class TestExifData(unittest.TestCase):
|
||||||
def test_exif_data(self):
|
def test_exif_data(self):
|
||||||
exif_data = ExifData(image_path="/path/to/image",
|
exif_data_dict = {
|
||||||
image_name="Image.jpeg",
|
"day": 2,
|
||||||
make="CAMERA",
|
"month": 2,
|
||||||
month=12,
|
"year": 2222,
|
||||||
day=12,
|
"make": "CAMERA",
|
||||||
year=2023,
|
"time": "10:10:10",
|
||||||
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.make == "CAMERA"
|
||||||
|
assert exif_data.year == 2222
|
||||||
|
assert exif_data.time == "10:10:10"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user