mattrguerra/meridian-outreach-vaultmainPrivate on GitHub, published here in full

weekly_partner_pipeline.py

Language Python2.4 KB44 lines

07-Automation/weekly_partner_pipeline.py

  1. #!/usr/bin/env python3
  2. """weekly_partner_pipeline.py: the deterministic engine of the Weekly Partner Client Pipeline.
  3. Lifetime value comes from a local, append-only order history
  4. (07-Automation/data/order_history.json), never from a single Plinth call:
  5. orders.fetch silently truncates large result sets (about 70 orders a response, no
  6. "has more" flag) and its offsets overlap, so an all-time query drops a long-standing
  7. client's newest orders. The history is seeded once from the roster workbook, then
  8. grown by day-sized pulls paged until a page adds nothing (see DECISIONS.md). An
  9. approved-merge registry (data/merge_registry.json) folds one person's duplicate
  10. accounts together at classify time; entries are added only with explicit approval.
  11. The script calls no API. The scheduled session makes the Plinth and Bitrix calls
  12. and hands the raw responses to it. The code lives in partner_pipeline/.
  13. Commands, in run order (the SOP has the full procedure):
  14. seed-baseline one time: load the roster workbook as per-customer baselines
  15. ingest merge raw orders.fetch pages into the history; prints
  16. "INGEST: parsed=N added=N", which the paging loop reads
  17. classify lifetime metrics and tiers from the history (partner-thresholds.md)
  18. verify no-shrink guardrail: exits 2 if any lifetime total decreased
  19. write-stubs create or upgrade client stubs (guarded)
  20. refresh-xml add or stamp clients in partner-client-master-list.xml (guarded)
  21. refresh-workbook regenerate the Drive-swap roster workbook (guarded)
  22. reconcile-deals absorb a Bitrix deals pull into census blocks and stubs (guarded)
  23. route propose outreach candidates; read-only on the vault and Bitrix
  24. outreach-pull-list list the deals whose stage history must be re-pulled
  25. outreach-audit build Bitrix_Pipeline_Outreach_Audit_<date>.xlsx (after refresh-workbook)
  26. Guarded stages refuse while partner-thresholds.md still has a TBD in the active mode.
  27. Run any command with --help for its flags. Install: pip install -r 07-Automation/requirements.txt
  28. """
  29. import sys
  30. from pathlib import Path
  31. # run_sample.py runs this file with runpy.run_path, which does not put the script's
  32. # directory on sys.path, so the package next to it has to be added by hand.
  33. sys.path.insert(0, str(Path(__file__).resolve().parent))
  34. from partner_pipeline.cli import main # noqa: E402
  35. if __name__ == "__main__":
  36. main()