Skip to content

Commit 252dd52

Browse files
fix: refactored approval message detection (#608)
1 parent a1fe36f commit 252dd52

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/kleinanzeigen_bot/__init__.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,10 @@ async def delete_ad(self, ad_cfg:Ad, published_ads:list[dict[str, Any]], *, dele
704704
ad_cfg.id = None
705705
return True
706706

707+
async def __check_publishing_result(self) -> bool:
708+
# Check for success messages
709+
return await self.web_check(By.ID, "checking-done", Is.DISPLAYED) or await self.web_check(By.ID, "not-completed", Is.DISPLAYED)
710+
707711
async def publish_ads(self, ad_cfgs:list[tuple[str, Ad, dict[str, Any]]]) -> None:
708712
count = 0
709713

@@ -720,8 +724,7 @@ async def publish_ads(self, ad_cfgs:list[tuple[str, Ad, dict[str, Any]]]) -> Non
720724
count += 1
721725

722726
await self.publish_ad(ad_file, ad_cfg, ad_cfg_orig, published_ads, AdUpdateStrategy.REPLACE)
723-
await self.web_await(lambda: self.web_check(By.ID, "checking-done", Is.DISPLAYED) or
724-
self.web_check(By.ID, "not-completed", Is.DISPLAYED), timeout=5 * 60)
727+
await self.web_await(self.__check_publishing_result, timeout = 5 * 60)
725728

726729
if self.config.publishing.delete_old_ads == "AFTER_PUBLISH" and not self.keep_old_ads:
727730
await self.delete_ad(ad_cfg, published_ads, delete_old_ads_by_title = False)
@@ -935,14 +938,6 @@ async def publish_ad(self, ad_file:str, ad_cfg:Ad, ad_cfg_orig:dict[str, Any], p
935938
ad_id = int(current_url_query_params.get("adId", [])[0])
936939
ad_cfg_orig["id"] = ad_id
937940

938-
# check for approval message
939-
try:
940-
approval_link_xpath = '//*[contains(@id, "not-completed")]//a[contains(@class, "to-my-ads-link")]'
941-
if await self.web_check(By.XPATH, approval_link_xpath, Is.DISPLAYED):
942-
await self.web_click(By.XPATH, approval_link_xpath)
943-
except TimeoutError:
944-
pass # nosec
945-
946941
# Update content hash after successful publication
947942
# Calculate hash on original config to ensure consistent comparison on restart
948943
ad_cfg_orig["content_hash"] = AdPartial.model_validate(ad_cfg_orig).update_content_hash().content_hash
@@ -988,8 +983,7 @@ async def update_ads(self, ad_cfgs:list[tuple[str, Ad, dict[str, Any]]]) -> None
988983
count += 1
989984

990985
await self.publish_ad(ad_file, ad_cfg, ad_cfg_orig, published_ads, AdUpdateStrategy.MODIFY)
991-
await self.web_await(lambda: self.web_check(By.ID, "checking-done", Is.DISPLAYED) or
992-
self.web_check(By.ID, "not-completed", Is.DISPLAYED), timeout = 5 * 60)
986+
await self.web_await(self.__check_publishing_result, timeout = 5 * 60)
993987

994988
LOG.info("############################################")
995989
LOG.info("DONE: updated %s", pluralize("ad", count))

0 commit comments

Comments
 (0)