#!/usr/bin/env python3 """Emit a Refined PrUn XIT ACT action-package JSON for a buy list - paste into the extension's "Import Action Package" (XIT ACT -> IMPORT) to pre-fill the CXPO buy tile for each material; you still click the real buy button yourself. See puga/actpkg.py for the schema/gotcha notes. puga actpkg "Nike PP1 BDE buildout" BDE:3 BBH:3 BSE:4 MCG:76 PE:750 puga actpkg "Nike PP1 BDE buildout" BDE:3 BBH:3 BSE:4 MCG:76 PE:750 --cx AI1 -o nike_pp1.json """ import argparse, json, sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from puga import config, actpkg def main(): ap = argparse.ArgumentParser() ap.add_argument("name", help="package name (letters/digits/spaces only - punctuation is stripped)") ap.add_argument("materials", nargs="+", help="TICKER:QTY pairs, e.g. BDE:3 MCG:76") ap.add_argument("--cx", default=config.DEFAULT_CX) ap.add_argument("-o", "--out", help="write to this file instead of stdout") a = ap.parse_args() mats = {} for m in a.materials: tk, _, qty = m.partition(":") if not qty: sys.exit(f"bad material spec {m!r}, expected TICKER:QTY") mats[tk] = float(qty) pkg = actpkg.build_package(a.name, mats, a.cx) text = json.dumps(pkg, indent=2) if a.out: Path(a.out).write_text(text) print(f"wrote {a.out}") else: print(text) if __name__ == "__main__": main()