From 0f2f842e04bd575ae70993bc61d0b19e99d2bcd8 Mon Sep 17 00:00:00 2001 From: Aron Date: Mon, 5 Jan 2026 14:14:42 +0100 Subject: [PATCH] fix degewo --- application_handler.py | 12 ++++++++++++ handlers/degewo_handler.py | 19 +++++++++++++++++++ handlers/gewobag_handler.py | 8 ++++++++ 3 files changed, 39 insertions(+) diff --git a/application_handler.py b/application_handler.py index ce88994..ea19cd7 100644 --- a/application_handler.py +++ b/application_handler.py @@ -147,6 +147,18 @@ class ApplicationHandler: for listing in listings: if self.has_applied(listing["id"]): logger.debug(f"Skip (applied): {listing['address']}") + # Add to results so notify_new_listings can handle it + results[listing["id"]] = { + "listing_id": listing["id"], + "company": self._detect_company(listing.get("link", "")), + "link": listing.get("link", ""), + "timestamp": listing.get("timestamp", ""), + "success": True, + "message": "Already applied successfully", + "address": listing.get("address", ""), + "rooms": listing.get("rooms", ""), + "price": listing.get("price", ""), + } continue result = await self.apply(listing) results[listing["id"]] = result diff --git a/handlers/degewo_handler.py b/handlers/degewo_handler.py index e4f5fe8..170f165 100644 --- a/handlers/degewo_handler.py +++ b/handlers/degewo_handler.py @@ -52,6 +52,25 @@ class DegewoHandler(BaseHandler): except Exception as e: logger.debug(f"[DEGEWO] Cookie banner dismiss failed: {e}") + # Save debug HTML and screenshot before checking button + try: + html_content = await page.content() + html_path = DATA_DIR / f"degewo_page_{listing['id']}.html" + with open(html_path, 'w', encoding='utf-8') as f: + f.write(html_content) + logger.info(f"[DEGEWO] Saved page HTML to {html_path}") + + # Check if listing is no longer available + if "nicht mehr verfügbar" in html_content or "Objekt nicht mehr verfügbar" in html_content: + logger.warning(f"[DEGEWO] Listing no longer available") + result["success"] = False + result["message"] = "Listing no longer available" + result["deactivated"] = True + await page.close() + return result + except Exception as e: + logger.warning(f"[DEGEWO] Could not save HTML: {e}") + logger.info("[DEGEWO] Looking for kontaktieren button...") apply_btn = await page.query_selector('a:has-text("kontaktieren"), button:has-text("kontaktieren"), a:has-text("Kontaktieren"), button:has-text("Kontaktieren")') if apply_btn and await apply_btn.is_visible(): diff --git a/handlers/gewobag_handler.py b/handlers/gewobag_handler.py index 62f1a23..77ef0ab 100644 --- a/handlers/gewobag_handler.py +++ b/handlers/gewobag_handler.py @@ -72,6 +72,14 @@ class GewobagHandler(BaseHandler): html_content = await iframe_page.content() with open(DATA_DIR / f"gewobag_wohnungshelden_{listing['id']}.html", "w", encoding="utf-8") as f: f.write(html_content) + + # Check for Wohnungshelden error messages + if "Fehler beim Laden" in html_content or "Beim Laden der Gesuchsdaten ist ein Fehler aufgetreten" in html_content: + logger.warning("[GEWOBAG] Wohnungshelden iframe shows error - may be transient, will retry") + result["success"] = False + result["message"] = "Wohnungshelden application form error - will retry later" + await iframe_page.close() + return result except Exception as e: logger.warning(f"[GEWOBAG] Could not save HTML: {e}")