From b2599771989aa5878824e6396ebd0d18321efc5c Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 22 Nov 2024 14:27:32 +0100 Subject: [PATCH] feat: if a category is not found try to lookup fallback category --- src/kleinanzeigen_bot/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/kleinanzeigen_bot/__init__.py b/src/kleinanzeigen_bot/__init__.py index c4e1a62..f30c93b 100644 --- a/src/kleinanzeigen_bot/__init__.py +++ b/src/kleinanzeigen_bot/__init__.py @@ -319,7 +319,18 @@ class KleinanzeigenBot(WebScrapingMixin): ad_cfg["id"] = int(ad_cfg["id"]) if ad_cfg["category"]: - ad_cfg["category"] = self.categories.get(ad_cfg["category"], ad_cfg["category"]) + resolved_category_id = self.categories.get(ad_cfg["category"]) + if not resolved_category_id and ">" in ad_cfg["category"]: + # this maps actually to the sonstiges/weiteres sub-category + parent_category = ad_cfg["category"].rpartition(">")[0].strip() + resolved_category_id = self.categories.get(parent_category) + if resolved_category_id: + LOG.warning( + "Category [%s] unknown. Using category [%s] with ID [%s] instead.", + ad_cfg["category"], parent_category, resolved_category_id) + + if resolved_category_id: + ad_cfg["category"] = resolved_category_id if ad_cfg["shipping_costs"]: ad_cfg["shipping_costs"] = str(round(utils.parse_decimal(ad_cfg["shipping_costs"]), 2))