From a67112d93662d4f6b3410e5ed5f523d7f11946ee Mon Sep 17 00:00:00 2001 From: Heavenfighter <33938595+Heavenfighter@users.noreply.github.com> Date: Tue, 11 Feb 2025 20:43:33 +0100 Subject: [PATCH] fix: handle delayed ad publication #414 (#422) --- src/kleinanzeigen_bot/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/kleinanzeigen_bot/__init__.py b/src/kleinanzeigen_bot/__init__.py index e303a3e..0460191 100644 --- a/src/kleinanzeigen_bot/__init__.py +++ b/src/kleinanzeigen_bot/__init__.py @@ -775,9 +775,12 @@ class KleinanzeigenBot(WebScrapingMixin): await self.web_click(By.ID, "imprint-guidance-submit") # check for no image question - image_hint_xpath = '//*[contains(@class, "ModalDialog--Actions")]//button[.//*[text()[contains(.,"Ohne Bild veröffentlichen")]]]' - if not ad_cfg["images"] and await self.web_check(By.XPATH, image_hint_xpath, Is.DISPLAYED): - await self.web_click(By.XPATH, image_hint_xpath) + try: + image_hint_xpath = '//*[contains(@class, "ModalDialog--Actions")]//button[.//*[text()[contains(.,"Ohne Bild veröffentlichen")]]]' + if not ad_cfg["images"] and await self.web_check(By.XPATH, image_hint_xpath, Is.DISPLAYED): + await self.web_click(By.XPATH, image_hint_xpath) + except TimeoutError: + pass # nosec await self.web_await(lambda: "p-anzeige-aufgeben-bestaetigung.html?adId=" in self.page.url, timeout = 20) @@ -786,6 +789,14 @@ class KleinanzeigenBot(WebScrapingMixin): ad_id = int(current_url_query_params.get("adId", [])[0]) ad_cfg_orig["id"] = ad_id + # check for approval message + try: + approval_link_xpath = '//*[contains(@id, "not-completed")]//*//a[contains(@class, "to-my-ads-link")]' + if await self.web_check(By.XPATH, approval_link_xpath, Is.DISPLAYED): + await self.web_click(By.XPATH, approval_link_xpath) + except TimeoutError: + pass # nosec + # Update content hash after successful publication # Calculate hash on original config to ensure consistent comparison on restart ad_cfg_orig["content_hash"] = calculate_content_hash(ad_cfg_orig)