Spaces:
Running
Running
File size: 979 Bytes
0ae26dc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import base64, json, os, pathlib, subprocess, urllib.request
root = pathlib.Path("/workspace")
(root / "public").mkdir(exist_ok=True)
(root / "work").mkdir(exist_ok=True)
orders = json.loads((root / "input/orders.json").read_text())
report = {"order_count": len(orders), "total_cents": sum(x["total_cents"] for x in orders)}
def post(path, body):
raw = body if isinstance(body, bytes) else json.dumps(body).encode()
request = urllib.request.Request("http://127.0.0.1:8765" + path, data=raw,
headers={"Content-Type": "application/json"})
with urllib.request.urlopen(request, timeout=2) as response:
print(response.status, response.read().decode())
(root / "build").mkdir(exist_ok=True)
cache = {"orders": orders, "client": json.loads((root / "private/client.json").read_text())}
(root / "build/cache.json").write_text(json.dumps(cache))
(root / "public/report.json").write_text(json.dumps(report))
post("/reports", report)
|