""" world_debt.py — the weight of the world's money. The dark ballast. Pulls the US national debt straight from the Treasury (no key). It's ~$39 trillion and grinding — a vast, slow, heavy number. Its day-to-day *change* is the churn; the total is a near-DC drone that only creeps. Yang ballast for a set that's otherwise all moon and weather. Emits: /gs/debt/total total public debt in dollars (a slow, heavy drift) /gs/debt/vel magnitude of the daily change ($/day) — the churn """ from __future__ import annotations import argparse import json import time import urllib.request from pythonosc.udp_client import SimpleUDPClient URL = ("https://api.fiscaldata.treasury.gov/services/api/fiscal_service" "/v2/accounting/od/debt_to_penny?sort=-record_date&page[size]=2") UA = "Godstrument/1.0 (live instrument)" def fetch(): req = urllib.request.Request(URL, headers={"User-Agent": UA}) with urllib.request.urlopen(req, timeout=30) as r: d = json.load(r)["data"] total = float(d[0]["tot_pub_debt_out_amt"]) prev = float(d[1]["tot_pub_debt_out_amt"]) if len(d) > 1 else total return total, abs(total - prev), d[0]["record_date"] def main(): ap = argparse.ArgumentParser() ap.add_argument("--host", default="127.0.0.1") ap.add_argument("--port", type=int, default=9000) ap.add_argument("--poll", type=float, default=3600.0, help="re-query every Ns") args = ap.parse_args() client = SimpleUDPClient(args.host, args.port) print(f"[debt] emitting /gs/debt/total|vel (US national debt) " f"(re-query every {args.poll:g}s)") total, vel, last = 0.0, 0.0, None next_poll, retry = 0.0, 60.0 while True: if time.time() >= next_poll: try: total, vel, date = fetch() if date != last: print(f" 💰 debt ${total/1e12:.3f}T (daily churn ${vel/1e9:.1f}B)") last = date next_poll, retry = time.time() + args.poll, 60.0 except Exception as e: # noqa print(f"[debt] warn: {e}; retry in {retry:.0f}s") next_poll = time.time() + retry retry = min(retry * 2, args.poll) client.send_message("/gs/debt/total", total) client.send_message("/gs/debt/vel", vel) time.sleep(5.0) if __name__ == "__main__": main()