From 7a3c5fc3de232261051be3cc9b6e7d60d7f48d5c Mon Sep 17 00:00:00 2001 From: Johannes Obermeier Date: Mon, 14 Jul 2025 22:16:54 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20handle=20missing=20.versand=5Fs=20for=20?= =?UTF-8?q?service=20categories=20like=20=E2=80=A6=20(#579)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are categories which are not require shipping and there is no shipping field ## ℹ️ Description For example category 297/298 does not require shipping, because its a service category. The current code did not handle that case and was searching for a path with .versand_s, but in this category, there is no such path. ## 📋 Changes Summary If the shipping_type is set to NOT_APPLICABLE in the configuration, the shipping assignment step is skipped instead of being forced. ### ⚙️ Type of Change Select the type(s) of change(s) included in this pull request: - [x] 🐞 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (adds new functionality without breaking existing usage) - [ ] 💥 Breaking change (changes that might break existing user setups, scripts, or configurations) ## ✅ Checklist Before requesting a review, confirm the following: - [x] I have reviewed my changes to ensure they meet the project's standards. - [x] I have tested my changes and ensured that all tests pass (`pdm run test`). - [x] I have formatted the code (`pdm run format`). - [x] I have verified that linting passes (`pdm run lint`). - [x] I have updated documentation where necessary. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --- src/kleinanzeigen_bot/__init__.py | 22 +++++++++++-------- .../resources/translations.de.yaml | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/kleinanzeigen_bot/__init__.py b/src/kleinanzeigen_bot/__init__.py index 808896e..0e0dc3c 100644 --- a/src/kleinanzeigen_bot/__init__.py +++ b/src/kleinanzeigen_bot/__init__.py @@ -766,16 +766,20 @@ class KleinanzeigenBot(WebScrapingMixin): ############################# # set shipping type/options/costs ############################# - if ad_cfg.type == "WANTED": - # special handling for ads of type WANTED since shipping is a special attribute for these - if ad_cfg.shipping_type in {"PICKUP", "SHIPPING"}: - shipping_value = "ja" if ad_cfg.shipping_type == "SHIPPING" else "nein" - try: - await self.web_select(By.XPATH, "//select[contains(@id, '.versand_s')]", shipping_value) - except TimeoutError: - LOG.warning("Failed to set shipping attribute for type '%s'!", ad_cfg.shipping_type) + shipping_type = ad_cfg.shipping_type + if shipping_type != "NOT_APPLICABLE": + if ad_cfg.type == "WANTED": + # special handling for ads of type WANTED since shipping is a special attribute for these + if shipping_type in {"PICKUP", "SHIPPING"}: + shipping_value = "ja" if shipping_type == "SHIPPING" else "nein" + try: + await self.web_select(By.XPATH, "//select[contains(@id, '.versand_s')]", shipping_value) + except TimeoutError: + LOG.warning("Failed to set shipping attribute for type '%s'!", shipping_type) + else: + await self.__set_shipping(ad_cfg, mode) else: - await self.__set_shipping(ad_cfg, mode) + LOG.debug("Shipping step skipped - reason: NOT_APPLICABLE") ############################# # set price diff --git a/src/kleinanzeigen_bot/resources/translations.de.yaml b/src/kleinanzeigen_bot/resources/translations.de.yaml index bc70186..3ab51bf 100644 --- a/src/kleinanzeigen_bot/resources/translations.de.yaml +++ b/src/kleinanzeigen_bot/resources/translations.de.yaml @@ -89,6 +89,7 @@ kleinanzeigen_bot/__init__.py: "Publishing ad '%s'...": "Veröffentliche Anzeige '%s'..." "Updating ad '%s'...": "Aktualisiere Anzeige '%s'..." "Failed to set shipping attribute for type '%s'!": "Fehler beim setzen des Versandattributs für den Typ '%s'!" + "Shipping step skipped - reason: NOT_APPLICABLE": "Versandschritt übersprungen: Versand nicht anwendbar (Status = NOT_APPLICABLE)" "# Payment form detected! Please proceed with payment.": "# Bestellformular gefunden! Bitte mit der Bezahlung fortfahren." " -> SUCCESS: ad published with ID %s": " -> ERFOLG: Anzeige mit ID %s veröffentlicht" " -> SUCCESS: ad updated with ID %s": " -> ERFOLG: Anzeige mit ID %s aktualisiert"