From c45c6992aef8cc12cef094b8be9bec45cbe78277 Mon Sep 17 00:00:00 2001 From: Aron Date: Thu, 1 Jan 2026 22:14:55 +0100 Subject: [PATCH] fix non-deactivating error --- BOTFATHER_COMMANDS.txt | 2 +- README.md | 2 +- handlers/degewo_handler.py | 3 +-- handlers/gesobau_handler.py | 11 ++++++----- handlers/gewobag_handler.py | 2 +- handlers/howoge_handler.py | 2 +- handlers/wbm_handler.py | 2 +- telegram_bot.py | 7 ++++++- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/BOTFATHER_COMMANDS.txt b/BOTFATHER_COMMANDS.txt index e538ae1..5ffec20 100644 --- a/BOTFATHER_COMMANDS.txt +++ b/BOTFATHER_COMMANDS.txt @@ -7,7 +7,7 @@ autopilot - Enable or disable automatic applications. Usage: autopilot on or aut status - Show current status and statistics (autopilot state, application counts by company) plot - Show weekly listing patterns (image) errorrate - Show autopilot success vs failure plot (image) -retryfailed - Retry all failed applications up to 3 times +retryfailed - Retry all failed applications up to 3 times (excludes deactivated listings) resetlistings - Delete all seen listings (forces re-check of all flats, does not affect stats or WGcompany) help - Show help and command usage diff --git a/README.md b/README.md index 77ec90f..816fe41 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ flowchart TD SelectHandler --> OpenPage[Open Listing Page] OpenPage --> Check404{404 or Deactivated?} - Check404 -- Yes --> MarkPermanent[Mark permanent_fail] + Check404 -- Yes --> MarkPermanent[Mark deactivated] MarkPermanent --> SaveFail[Save to applications.json] SaveFail --> NotifyFail[Notify: Application Failed] diff --git a/handlers/degewo_handler.py b/handlers/degewo_handler.py index 5bef474..e4f5fe8 100644 --- a/handlers/degewo_handler.py +++ b/handlers/degewo_handler.py @@ -29,8 +29,7 @@ class DegewoHandler(BaseHandler): logger.warning(f"[DEGEWO] Listing is down (404): {listing['link']}") result["success"] = False result["message"] = "Listing is no longer available (404). Application impossible. Will not retry." - result["permanent_fail"] = True - await page.close() + result["deactivated"] = True return result # Check for 'INSERAT DEAKTIVIERT' (deactivated listing) diff --git a/handlers/gesobau_handler.py b/handlers/gesobau_handler.py index 17a83a0..352a989 100644 --- a/handlers/gesobau_handler.py +++ b/handlers/gesobau_handler.py @@ -26,7 +26,7 @@ class GesobauHandler(BaseHandler): logger.warning(f"[GESOBAU] Listing is down (404): {listing['link']}") result["success"] = False result["message"] = "Listing is no longer available (404). Application impossible. Will not retry." - result["permanent_fail"] = True + result["deactivated"] = True await page.close() return result @@ -34,9 +34,9 @@ class GesobauHandler(BaseHandler): await self.handle_cookies(page) await self.handle_consent(page) - # Save HTML after modal handling for debugging + # Save HTML after modal handling for debugging and check for deactivation + html_content = await page.content() try: - html_content = await page.content() with open(DATA_DIR / "gesobau_debug.html", "w", encoding="utf-8") as f: f.write(html_content) except Exception as e: @@ -45,8 +45,9 @@ class GesobauHandler(BaseHandler): # Tailored 404 detection: Angebot nicht mehr verfügbar if "Angebot nicht mehr verfügbar" in html_content: logger.warning("[GESOBAU] Permanent fail: Angebot nicht mehr verfügbar") - result["permanent_fail"] = True - result["message"] = "Listing is no longer available (Angebot nicht mehr verfügbar). Marked as permanent fail." + result["deactivated"] = True + result["message"] = "Listing is no longer available (Angebot nicht mehr verfügbar). Marked as deactivated." + await page.close() return result # Look for application button diff --git a/handlers/gewobag_handler.py b/handlers/gewobag_handler.py index f96d310..0fa2731 100644 --- a/handlers/gewobag_handler.py +++ b/handlers/gewobag_handler.py @@ -26,7 +26,7 @@ class GewobagHandler(BaseHandler): logger.warning(f"[GEWOBAG] Listing is down (404): {listing['link']}") result["success"] = False result["message"] = "Listing is no longer available (404). Application impossible. Will not retry." - result["permanent_fail"] = True + result["deactivated"] = True return result # Always handle cookies and consent before anything else diff --git a/handlers/howoge_handler.py b/handlers/howoge_handler.py index 738dc83..cae3b2a 100644 --- a/handlers/howoge_handler.py +++ b/handlers/howoge_handler.py @@ -27,7 +27,7 @@ class HowogeHandler(BaseHandler): logger.warning(f"[HOWOGE] Listing is down (404): {listing['link']}") result["success"] = False result["message"] = "Listing is no longer available (404). Application impossible. Will not retry." - result["permanent_fail"] = True + result["deactivated"] = True await page.close() return result diff --git a/handlers/wbm_handler.py b/handlers/wbm_handler.py index 7c2bb76..9daa2da 100644 --- a/handlers/wbm_handler.py +++ b/handlers/wbm_handler.py @@ -43,7 +43,7 @@ class WBMHandler(BaseHandler): if page_text: for err in error_texts: if err in page_text: - result["permanent_fail"] = True + result["deactivated"] = True result["message"] = "Listing is no longer available (404 detected on WBM)." logger.warning(f"[WBM] Permanent fail: {err}") await page.close() diff --git a/telegram_bot.py b/telegram_bot.py index 0ee917e..ae5e572 100644 --- a/telegram_bot.py +++ b/telegram_bot.py @@ -168,7 +168,12 @@ class TelegramBot: for handler in self.app_handler.handlers.values(): handler.context = self.app_handler.context applications = self.app_handler.load_applications() - failed = [app for app in applications.values() if not app.get("success") and app.get("retries", 0) < max_retries] + failed = [ + app for app in applications.values() + if not app.get("success") + and app.get("retries", 0) < max_retries + and not app.get("deactivated", False) + ] await self._send_message(f"🔄 Retrying {len(failed)} failed applications (max retries: {max_retries})...") if not failed: await self._send_message("✅ No failed applications to retry (or all reached max retries).")