Auto-sync permit competitors in monitoring PF
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 35s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 35s
This commit is contained in:
@@ -15,11 +15,11 @@ from app.models import Project
|
||||
from app.services.monitor import (
|
||||
BAYUT_ENABLED,
|
||||
add_competitor_url,
|
||||
add_competitor_urls,
|
||||
resolve_our_permit,
|
||||
_format_listing_added,
|
||||
notify_project_changes,
|
||||
run_check_all,
|
||||
run_check_for_project,
|
||||
suggest_similar,
|
||||
sync_permit_competitors,
|
||||
)
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ def cmd_add_listing(payload: dict[str, Any]) -> None:
|
||||
listing, err = add_competitor_url(db, project, url)
|
||||
if err:
|
||||
_fail(err)
|
||||
notify_project_changes(project, [_format_listing_added(project, listing, auto=False)])
|
||||
_write({"listing_id": listing.id})
|
||||
finally:
|
||||
db.close()
|
||||
@@ -79,7 +80,27 @@ def cmd_add_listings(payload: dict[str, Any]) -> None:
|
||||
project = db.get(Project, project_id)
|
||||
if not project:
|
||||
_fail("project not found")
|
||||
_write(add_competitor_urls(db, project, urls))
|
||||
added = 0
|
||||
skipped = 0
|
||||
errors: list[str] = []
|
||||
notifications: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for raw in urls:
|
||||
url = str(raw or "").strip()
|
||||
if not url or url in seen:
|
||||
continue
|
||||
seen.add(url)
|
||||
listing, err = add_competitor_url(db, project, url)
|
||||
if err == "Это объявление уже добавлено в проект":
|
||||
skipped += 1
|
||||
elif err:
|
||||
errors.append(err)
|
||||
else:
|
||||
added += 1
|
||||
notifications.append(_format_listing_added(project, listing, auto=False))
|
||||
if notifications:
|
||||
notify_project_changes(project, notifications)
|
||||
_write({"added": added, "skipped": skipped, "errors": errors})
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@@ -101,8 +122,10 @@ def cmd_suggest(payload: dict[str, Any]) -> None:
|
||||
project = db.get(Project, project_id)
|
||||
if not project:
|
||||
_fail("project not found")
|
||||
permit = resolve_our_permit(project)
|
||||
suggestions = suggest_similar(project, our_permit=permit)
|
||||
changes, suggestions, permit = sync_permit_competitors(db, project)
|
||||
db.commit()
|
||||
if changes:
|
||||
notify_project_changes(project, changes)
|
||||
_write({
|
||||
"our_permit": permit,
|
||||
"bayut_enabled": BAYUT_ENABLED,
|
||||
|
||||
Reference in New Issue
Block a user