From 8e3e03d6cbd31f8a316ee96bf786a1645ef2826c Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 27 Apr 2022 17:06:26 +0200 Subject: [PATCH] Sort images per path Sort images on a per path/pattern basis instead of sorting all of them at once after reading them. Also using list instead of set. --- kleinanzeigen_bot/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kleinanzeigen_bot/__init__.py b/kleinanzeigen_bot/__init__.py index 1a60d85..23a92b1 100644 --- a/kleinanzeigen_bot/__init__.py +++ b/kleinanzeigen_bot/__init__.py @@ -259,18 +259,21 @@ class KleinanzeigenBot(SeleniumMixin): ad_cfg["shipping_costs"] = str(utils.parse_decimal(ad_cfg["shipping_costs"])) if ad_cfg["images"]: - images = set() + images = list() for image_pattern in ad_cfg["images"]: + pattern_images = set() ad_dir = os.path.dirname(ad_file) for image_file in glob.glob(image_pattern, root_dir = ad_dir, recursive = True): _, image_file_ext = os.path.splitext(image_file) ensure(image_file_ext.lower() in {".gif", ".jpg", ".jpeg", ".png"}, f"Unsupported image file type [{image_file}]") if os.path.isabs(image_file): - images.add(image_file) + pattern_images.add(image_file) else: - images.add(abspath(image_file, relative_to = ad_file)) + pattern_images.add(abspath(image_file, relative_to = ad_file)) + for image_file in sorted(pattern_images): + images.append(image_file) ensure(images or not ad_cfg["images"], f"No images found for given file patterns {ad_cfg['images']} at {ad_dir}") - ad_cfg["images"] = sorted(images) + ad_cfg["images"] = images ads.append(( ad_file,