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.
This commit is contained in:
Jens Bergmann
2025-02-15 17:12:08 +01:00
committed by Sebastian Thomschke
parent 34b2bc6550
commit 610615367c

View File

@@ -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,