This commit is contained in:
Aron Petau 2026-01-05 15:46:30 +01:00
parent 0f2f842e04
commit bc06db593b

View file

@ -97,6 +97,10 @@ class ApplicationHandler:
if application_results is not None: if application_results is not None:
if listing["id"] in application_results: if listing["id"] in application_results:
result = application_results[listing["id"]] result = application_results[listing["id"]]
# Skip already-applied listings (no notification needed)
if result.get("skipped"):
logger.debug(f"Skip notification for already-applied: {listing['address']}")
continue # Skip to next listing
if result["success"]: if result["success"]:
message += f"\n\n\ud83e\udd16 <b>Auto-applied!</b> ({result['company']})" message += f"\n\n\ud83e\udd16 <b>Auto-applied!</b> ({result['company']})"
if result["message"]: if result["message"]:
@ -145,21 +149,24 @@ class ApplicationHandler:
if self.context is None: if self.context is None:
raise RuntimeError("browser_context is None in apply_to_listings. This should never happen.") raise RuntimeError("browser_context is None in apply_to_listings. This should never happen.")
for listing in listings: for listing in listings:
if self.has_applied(listing["id"]): # Check if we've already successfully applied
logger.debug(f"Skip (applied): {listing['address']}") applications = self.load_applications()
# Add to results so notify_new_listings can handle it if listing["id"] in applications:
results[listing["id"]] = { app = applications[listing["id"]]
"listing_id": listing["id"], if app.get("success", False):
"company": self._detect_company(listing.get("link", "")), # Check if it's the same listing (same link) or a reused ID
"link": listing.get("link", ""), if app.get("link") == listing.get("link"):
"timestamp": listing.get("timestamp", ""), logger.debug(f"Skip (applied): {listing['address']}")
"success": True, # Mark as skipped so notify_new_listings knows not to send notification
"message": "Already applied successfully", results[listing["id"]] = {
"address": listing.get("address", ""), "listing_id": listing["id"],
"rooms": listing.get("rooms", ""), "skipped": True, # Flag to prevent duplicate notifications
"price": listing.get("price", ""), }
} continue
continue else:
# Same ID but different link - companies reused the ID for a new listing
logger.info(f"Reused ID detected for {listing['address']}: old link={app.get('link')}, new link={listing.get('link')}")
# Treat as new listing and apply
result = await self.apply(listing) result = await self.apply(listing)
results[listing["id"]] = result results[listing["id"]] = result
self.save_application(result) self.save_application(result)