From bc06db593b0492ac74e3436715d904e6901cc294 Mon Sep 17 00:00:00 2001 From: Aron Date: Mon, 5 Jan 2026 15:46:30 +0100 Subject: [PATCH] logic --- application_handler.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/application_handler.py b/application_handler.py index ea19cd7..a4e36a4 100644 --- a/application_handler.py +++ b/application_handler.py @@ -97,6 +97,10 @@ class ApplicationHandler: if application_results is not None: if listing["id"] in application_results: 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"]: message += f"\n\n\ud83e\udd16 Auto-applied! ({result['company']})" if result["message"]: @@ -145,21 +149,24 @@ class ApplicationHandler: if self.context is None: raise RuntimeError("browser_context is None in apply_to_listings. This should never happen.") 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 + # Check if we've already successfully applied + applications = self.load_applications() + if listing["id"] in applications: + app = applications[listing["id"]] + if app.get("success", False): + # Check if it's the same listing (same link) or a reused ID + if app.get("link") == listing.get("link"): + logger.debug(f"Skip (applied): {listing['address']}") + # Mark as skipped so notify_new_listings knows not to send notification + results[listing["id"]] = { + "listing_id": listing["id"], + "skipped": True, # Flag to prevent duplicate notifications + } + 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) results[listing["id"]] = result self.save_application(result)