upd
This commit is contained in:
parent
155ab39368
commit
8e69e30387
1 changed files with 29 additions and 20 deletions
|
|
@ -67,34 +67,40 @@ class ApplicationHandler:
|
||||||
Send a Telegram notification for each new listing.
|
Send a Telegram notification for each new listing.
|
||||||
Includes application result if autopilot was enabled.
|
Includes application result if autopilot was enabled.
|
||||||
"""
|
"""
|
||||||
if not new_listings:
|
|
||||||
return
|
|
||||||
|
|
||||||
for listing in new_listings:
|
for listing in new_listings:
|
||||||
link = listing.get('link', 'https://www.inberlinwohnen.de/wohnungsfinder/')
|
link = listing.get('link', 'https://www.inberlinwohnen.de/wohnungsfinder/')
|
||||||
# Detect company for header
|
|
||||||
company = self._detect_company(link)
|
company = self._detect_company(link)
|
||||||
|
if company == "wgcompany":
|
||||||
|
continue # skip WGCompany listings for main handler
|
||||||
company_label = company.capitalize() if company != "unknown" else "Wohnung"
|
company_label = company.capitalize() if company != "unknown" else "Wohnung"
|
||||||
message = (
|
message = (
|
||||||
f"🏠 <b>[{company_label}] Neue Wohnung!</b>\n\n"
|
f"\ud83c\udfe0 <b>[{company_label}] Neue Wohnung!</b>\n\n"
|
||||||
f"🚪 <b>{listing['rooms']}</b>\n"
|
f"\ud83d\udeaa <b>{listing['rooms']}</b>\n"
|
||||||
f"📐 {listing['size']}\n"
|
f"\ud83d\udcd0 {listing['size']}\n"
|
||||||
f"💰 {listing['price']}\n"
|
f"\ud83d\udcb0 {listing['price']}\n"
|
||||||
f"📍 {listing['address']}\n\n"
|
f"\ud83d\udccd {listing['address']}\n\n"
|
||||||
f"👉 <a href=\"{link}\">Alle Details</a>"
|
f"\ud83d\udc49 <a href=\"{link}\">Alle Details</a>"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add autopilot/apply status if attempted
|
# Always show autopilot/apply status for clarity
|
||||||
if application_results and listing["id"] in application_results:
|
if application_results is not None:
|
||||||
result = application_results[listing["id"]]
|
if listing["id"] in application_results:
|
||||||
if result["success"]:
|
result = application_results[listing["id"]]
|
||||||
message += f"\n\n🤖 <b>Auto-applied!</b> ({result['company']})"
|
if result["success"]:
|
||||||
if result["message"]:
|
message += f"\n\n\ud83e\udd16 <b>Auto-applied!</b> ({result['company']})"
|
||||||
message += f"\n<i>{result['message']}</i>"
|
if result["message"]:
|
||||||
|
message += f"\n<i>{result['message']}</i>"
|
||||||
|
else:
|
||||||
|
# Handler attempted but failed
|
||||||
|
fail_msg = result.get("message") or "Unknown error during application."
|
||||||
|
message += f"\n\n\u26a0\ufe0f <b>Auto-apply failed</b> ({result['company']})"
|
||||||
|
message += f"\n<b>Reason:</b> <i>{html.escape(fail_msg)}</i>"
|
||||||
else:
|
else:
|
||||||
message += f"\n\n⚠️ <b>Auto-apply failed</b> ({result['company']})"
|
# Should not happen if logic is correct, but fallback
|
||||||
if result["message"]:
|
message += "\n\n\u2139\ufe0f <b>No application attempted (internal logic error)</b>"
|
||||||
message += f"\n<i>{result['message']}</i>"
|
else:
|
||||||
|
# Autopilot was off or not attempted at all
|
||||||
|
message += "\n\n\u2139\ufe0f <b>No application attempted (autopilot off)</b>"
|
||||||
|
|
||||||
# Send via TelegramBot if available
|
# Send via TelegramBot if available
|
||||||
if hasattr(self, 'telegram_bot') and self.telegram_bot:
|
if hasattr(self, 'telegram_bot') and self.telegram_bot:
|
||||||
|
|
@ -102,6 +108,9 @@ class ApplicationHandler:
|
||||||
self.telegram_bot._send_message(message)
|
self.telegram_bot._send_message(message)
|
||||||
else:
|
else:
|
||||||
logger.info(f"[TELEGRAM] Would send message for: {listing['address']} ({listing['rooms']}, {listing['size']}, {listing['price']})")
|
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:
|
async def apply_to_listings(self, listings: list[dict]) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue