mattrguerra/meridian-skillsmainPrivate on GitHub, published here in full

batch_web.py

Language Python3.3 KB72 lines

skills/client-enrich/scripts/batch_web.py

  1. #!/usr/bin/env python3
  2. """
  3. batch_web.py: write-back for web-search signals (client-enrich, no-credit mode).
  4. For stubs where company LinkedIn posts were unavailable, this fills the Signals
  5. section from web-search findings while preserving Person (from frontmatter) and
  6. Company (minimal) content. Uses enrich_writeback.py so the vault contract holds.
  7. Usage:
  8. python3 batch_web.py --batch checkin_batch.json --signals web_signals.json \
  9. --stubdir "/path/03-Clients/Check-In" --script "/path/enrich_writeback.py" [--date YYYY-MM-DD]
  10. web_signals.json: { "Stub File.md": {"signals": ["- 2026: ...", ...],
  11. "sources": ["- https://...", ...]}, ... }
  12. signals/sources are pre-formatted markdown bullet lines. If a company yielded
  13. nothing, pass {"signals": [], "sources": []} and a [TBD] line is written.
  14. """
  15. import argparse, json, os, subprocess, sys, datetime, tempfile
  16. def main():
  17. ap = argparse.ArgumentParser()
  18. ap.add_argument("--batch", required=True)
  19. ap.add_argument("--signals", required=True)
  20. ap.add_argument("--stubdir", required=True)
  21. ap.add_argument("--script", required=True)
  22. ap.add_argument("--date", default=datetime.date.today().isoformat())
  23. args = ap.parse_args()
  24. batch = {r["file"]: r for r in json.load(open(args.batch, encoding="utf-8"))}
  25. sig = json.load(open(args.signals, encoding="utf-8"))
  26. rows = []
  27. for fname, data in sig.items():
  28. r = batch.get(fname, {"file": fname})
  29. person = []
  30. if r.get("title"): person.append(f"- Title: {r['title']}")
  31. if r.get("seniority"): person.append(f"- Seniority: {r['seniority']}")
  32. loc = ", ".join([x for x in [r.get("city"), r.get("state")] if x])
  33. if loc: person.append(f"- Location: {loc}")
  34. if r.get("linkedin"): person.append(f"- LinkedIn: {r['linkedin']}")
  35. person = person or ["[TBD]"]
  36. company = []
  37. if r.get("company"): company.append(f"- {r['company']}")
  38. if r.get("company_li"): company.append(f"- LinkedIn: {r['company_li']}")
  39. company.append("- [TBD: firmographics (revenue/headcount/funding) not pulled, Apollo skipped this run]")
  40. signals = list(data.get("signals") or [])
  41. sources = list(data.get("sources") or [])
  42. if not signals:
  43. signals = ["[TBD: no recent public news found via web search]"]
  44. sources.append(f"- Web search, {args.date}")
  45. sources.append("- Stub frontmatter (prior enrichment)")
  46. payload = {"frontmatter": {}, "person": person, "company": company,
  47. "signals": signals, "sources": sources}
  48. with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as tf:
  49. json.dump(payload, tf); pj = tf.name
  50. res = subprocess.run([sys.executable, args.script, "--stub",
  51. os.path.join(args.stubdir, fname), "--payload", pj,
  52. "--date", args.date], capture_output=True, text=True)
  53. os.unlink(pj)
  54. rows.append((fname, len([s for s in signals if not s.startswith("[TBD")]),
  55. res.returncode == 0, res.stderr.strip()[:120]))
  56. ok = sum(1 for _,_,k,_ in rows if k)
  57. print(f"WROTE {ok}/{len(rows)} stubs OK")
  58. for f, n, k, err in rows:
  59. print(f" {f[:34]:36} | {n} sig | {'OK' if k else 'FAIL: '+err}")
  60. if __name__ == "__main__":
  61. main()