From 610615367ce714a22d26ae0404569764d6af6d09 Mon Sep 17 00:00:00 2001 From: Jens Bergmann <1742418+1cu@users.noreply.github.com> Date: Sat, 15 Feb 2025 17:12:08 +0100 Subject: [PATCH] fix: consolidate description text processing (#432) Consolidate description text processing into __get_description_with_affixes method: - Move @ -> (at) replacement into the method - Remove duplicate prefix/suffix handling code - Ensure consistent description text processing in one place This fixes #432 by ensuring consistent handling of description affixes and text transformations. --- src/kleinanzeigen_bot/__init__.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/kleinanzeigen_bot/__init__.py b/src/kleinanzeigen_bot/__init__.py index 453b3d9..4e30c7c 100644 --- a/src/kleinanzeigen_bot/__init__.py +++ b/src/kleinanzeigen_bot/__init__.py @@ -351,13 +351,8 @@ class KleinanzeigenBot(WebScrapingMixin): if not self.__check_ad_republication(ad_cfg, ad_cfg_orig, ad_file_relative): continue - # Get prefix/suffix from ad config if present, otherwise use defaults - prefix = ad_cfg.get("prefix", self.config["ad_defaults"]["description"]["prefix"] or "") - suffix = ad_cfg.get("suffix", self.config["ad_defaults"]["description"]["suffix"] or "") - - # Combine description parts - ad_cfg["description"] = prefix + (ad_cfg["description"] or "") + suffix - ad_cfg["description"] = ad_cfg["description"].replace("@", "(at)") + # Get description with prefix/suffix from ad config if present, otherwise use defaults + ad_cfg["description"] = self.__get_description_with_affixes(ad_cfg) # Validate total length ensure(len(ad_cfg["description"]) <= 4000, @@ -1098,8 +1093,9 @@ class KleinanzeigenBot(WebScrapingMixin): else get_description_affixes(self.config, prefix=False) ) - # Combine the parts + # Combine the parts and replace @ with (at) final_description = str(prefix) + str(description_text) + str(suffix) + final_description = final_description.replace("@", "(at)") # Validate length ensure(len(final_description) <= 4000,