- world_debt.py + world_econ.py: US national debt + inflation (the dark half) - concept groups: "the shadow" / "the bright" — group sources by feeling - named templates: hub save_patch/load_patch + console TEMPLATES panel - editing console: runtime add/remove/set route + make_group; drag-to-patch, shift-click inspector, cmd-select grouping in the viz - planetary orbital LFOs per group; almanac + ephemeris workers - Web MIDI (out + learn) in the console; strudel/godstrument.md starter kit Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
"""
|
|
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
|
|
last_poll = 0.0
|
|
while True:
|
|
try:
|
|
if time.time() - last_poll > args.poll or total == 0.0:
|
|
total, vel, date = fetch()
|
|
last_poll = time.time()
|
|
if date != last:
|
|
print(f" 💰 debt ${total/1e12:.3f}T (daily churn ${vel/1e9:.1f}B)")
|
|
last = date
|
|
client.send_message("/gs/debt/total", total)
|
|
client.send_message("/gs/debt/vel", vel)
|
|
except Exception as e: # noqa
|
|
print(f"[debt] warn: {e}")
|
|
time.sleep(5.0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|