Files
bhushanct c1eef4c6aa Initial commit: Screen Leads app
Screen-capture lead tool: capture agent, Claude vision extractor with
pluggable site recipes (LinkedIn), canonical funnel model, SQLite storage,
FastAPI backend, dashboard, and setup/run scripts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 07:43:33 +05:30

73 lines
1.6 KiB
Python

"""FastAPI backend: run controls, status, and lead queries; serves the dashboard."""
from __future__ import annotations
from pathlib import Path
from typing import Optional
from fastapi import FastAPI
from fastapi.responses import HTMLResponse, JSONResponse
import config
from core.controller import controller
from db import database
app = FastAPI(title="Screen Leads")
_ROOT = Path(__file__).resolve().parent.parent
_DASHBOARD_DIR = _ROOT / "dashboard"
_DASHBOARD = _DASHBOARD_DIR / "index.html"
_SUPPORT = _DASHBOARD_DIR / "support.html"
@app.on_event("startup")
def _startup() -> None:
database.init_db()
@app.get("/", response_class=HTMLResponse)
def index() -> str:
return _DASHBOARD.read_text(encoding="utf-8")
@app.get("/support", response_class=HTMLResponse)
def support() -> str:
return _SUPPORT.read_text(encoding="utf-8")
# --- run controls ------------------------------------------------------------
@app.post("/api/start")
def start():
return controller.start()
@app.post("/api/pause")
def pause():
return controller.pause()
@app.post("/api/resume")
def resume():
return controller.resume()
@app.post("/api/stop")
def stop():
return controller.stop()
@app.get("/api/status")
def status():
return {**controller.status(), "stage_counts": database.stage_counts()}
# --- leads -------------------------------------------------------------------
@app.get("/api/leads")
def leads(stage: Optional[str] = None):
return JSONResponse(database.list_leads(stage))
@app.post("/api/leads/{lead_id}/stage")
def set_stage(lead_id: int, stage: str):
database.set_stage(lead_id, stage)
return {"ok": True}