logic
This commit is contained in:
parent
0f2f842e04
commit
bc06db593b
1 changed files with 22 additions and 15 deletions
|
|
@ -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
|
||||||
|
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']}")
|
logger.debug(f"Skip (applied): {listing['address']}")
|
||||||
# Add to results so notify_new_listings can handle it
|
# Mark as skipped so notify_new_listings knows not to send notification
|
||||||
results[listing["id"]] = {
|
results[listing["id"]] = {
|
||||||
"listing_id": listing["id"],
|
"listing_id": listing["id"],
|
||||||
"company": self._detect_company(listing.get("link", "")),
|
"skipped": True, # Flag to prevent duplicate notifications
|
||||||
"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
|
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue