""" check_recent_leads.py — read-only diagnostic for "I just generated a lead and it's not showing where I expect." Prints the most recent N leads with every field a filter/queue check reads: pipeline_stage and phone_status (Cold Call Desk's CALL_QUEUE_STAGES filter), industry_tag (Category filter), country (Country filter), and source_prompt (the Source filter's leadSource() derivation). uv run python scripts/check_recent_leads.py # last 10 uv run python scripts/check_recent_leads.py --limit 25 """ from __future__ import annotations import argparse import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from sqlalchemy import select # noqa: E402 from app.database import SessionLocal # noqa: E402 from app.models import Lead # noqa: E402 def main() -> int: parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("--limit", type=int, default=10) args = parser.parse_args() db = SessionLocal() try: rows = list( db.scalars( select(Lead).order_by(Lead.created_at.desc(), Lead.id.desc()).limit(args.limit) ).all() ) if not rows: print("No leads in the database at all.") return 0 print(f"Most recent {len(rows)} lead(s):\n") for lead in rows: print(f"#{lead.id} {lead.company_name}") print(f" created_at: {lead.created_at}") print(f" pipeline_stage: {lead.pipeline_stage!r}") print(f" phone_status: {lead.phone_status!r}") print(f" industry_tag: {lead.industry_tag!r}") print(f" country: {lead.country!r}") print(f" source_prompt: {lead.source_prompt!r}") print() return 0 finally: db.close() if __name__ == "__main__": sys.exit(main())