#!/usr/bin/env python3 """Step 5 — generate the daily 'consistent smart-money' digest. python scripts/05_digest.py # last 24h, live fresh moves python scripts/05_digest.py --hours 48 # widen the window python scripts/05_digest.py --no-live # skip live pull (traders only) Reads the already-computed metrics table (data/wallets.csv), applies the consistency wedge, optionally pulls each trader's recent moves live, scores them, and writes a Markdown digest to data/digest_.md — the content unit for a newsletter / Telegram post / X thread. """ import argparse import sys from pathlib import Path import pandas as pd sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from pmct import digest as dg from pmct.client import PolymarketClient from pmct.util import load_config, cache_path def main(): ap = argparse.ArgumentParser() ap.add_argument("--hours", type=int, default=24) ap.add_argument("--no-live", action="store_true", help="skip the live fresh-moves pull") args = ap.parse_args() cfg = load_config() wallets_csv = cache_path(cfg, "wallets.csv") if not wallets_csv.exists(): raise SystemExit("No data/wallets.csv. Run 02_analyze_wallets.py first.") df = pd.read_csv(wallets_csv) sel_cfg = dg.SelectionConfig() selected = dg.select_smart_money(df, sel_cfg) print(f"Selected {len(selected)}/{len(df)} traders (consistency wedge).") moves = [] if not args.no_live and not selected.empty: client = PolymarketClient(sleep_sec=0.15) print(f"Pulling fresh moves (last {args.hours}h) for {len(selected)} traders…") moves = dg.fresh_moves(client, selected, hours=args.hours) print(f" {len(moves)} fresh moves scored.") md = dg.render_markdown(selected, moves, hours=args.hours) out = cache_path(cfg, f"digest_{pd.Timestamp.now('UTC'):%Y%m%d_%H%M}.md") out.write_text(md, encoding="utf-8") print(f"\nDigest -> {out}\n") print(md[:1600]) if __name__ == "__main__": main()