From 8e69e30387c3d002b28e61b9b440cd608dda2dd3 Mon Sep 17 00:00:00 2001 From: Aron Date: Mon, 29 Dec 2025 10:27:14 +0100 Subject: [PATCH] upd --- application_handler.py | 49 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/application_handler.py b/application_handler.py index 65f3d83..4721c40 100644 --- a/application_handler.py +++ b/application_handler.py @@ -67,34 +67,40 @@ class ApplicationHandler: Send a Telegram notification for each new listing. Includes application result if autopilot was enabled. """ - if not new_listings: - return - for listing in new_listings: link = listing.get('link', 'https://www.inberlinwohnen.de/wohnungsfinder/') - # Detect company for header company = self._detect_company(link) + if company == "wgcompany": + continue # skip WGCompany listings for main handler company_label = company.capitalize() if company != "unknown" else "Wohnung" message = ( - f"šŸ  [{company_label}] Neue Wohnung!\n\n" - f"🚪 {listing['rooms']}\n" - f"šŸ“ {listing['size']}\n" - f"šŸ’° {listing['price']}\n" - f"šŸ“ {listing['address']}\n\n" - f"šŸ‘‰ Alle Details" + f"\ud83c\udfe0 [{company_label}] Neue Wohnung!\n\n" + f"\ud83d\udeaa {listing['rooms']}\n" + f"\ud83d\udcd0 {listing['size']}\n" + f"\ud83d\udcb0 {listing['price']}\n" + f"\ud83d\udccd {listing['address']}\n\n" + f"\ud83d\udc49 Alle Details" ) - # Add autopilot/apply status if attempted - if application_results and listing["id"] in application_results: - result = application_results[listing["id"]] - if result["success"]: - message += f"\n\nšŸ¤– Auto-applied! ({result['company']})" - if result["message"]: - message += f"\n{result['message']}" + # Always show autopilot/apply status for clarity + if application_results is not None: + if listing["id"] in application_results: + result = application_results[listing["id"]] + if result["success"]: + message += f"\n\n\ud83e\udd16 Auto-applied! ({result['company']})" + if result["message"]: + message += f"\n{result['message']}" + else: + # Handler attempted but failed + fail_msg = result.get("message") or "Unknown error during application." + message += f"\n\n\u26a0\ufe0f Auto-apply failed ({result['company']})" + message += f"\nReason: {html.escape(fail_msg)}" else: - message += f"\n\nāš ļø Auto-apply failed ({result['company']})" - if result["message"]: - message += f"\n{result['message']}" + # Should not happen if logic is correct, but fallback + message += "\n\n\u2139\ufe0f No application attempted (internal logic error)" + else: + # Autopilot was off or not attempted at all + message += "\n\n\u2139\ufe0f No application attempted (autopilot off)" # Send via TelegramBot if available if hasattr(self, 'telegram_bot') and self.telegram_bot: @@ -102,6 +108,9 @@ class ApplicationHandler: self.telegram_bot._send_message(message) else: logger.info(f"[TELEGRAM] Would send message for: {listing['address']} ({listing['rooms']}, {listing['size']}, {listing['price']})") + self.telegram_bot._send_message(message) + else: + logger.info(f"[TELEGRAM] Would send message for: {listing['address']} ({listing['rooms']}, {listing['size']}, {listing['price']})") async def apply_to_listings(self, listings: list[dict]) -> dict: """