Files
game-kit/gamehall/ops/gamehall-rollup.sh
T
Eric WagonerandClaude Opus 5.5 1dbf5763e1 The hall counts its visitors: a digest, a nightly rollup, and the games it sends people to
gamehall/ops holds the traffic counter, the visitors digest and the
nightly rollup, installed by gamehall/deploy.sh; the gamehall-visitors
skill reads them. The hall now sends its origin as referrer, so a game
can tell who came from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG
2026-09-26 12:41:55 -04:00

30 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Nightly rollup: one JSON line per day in /var/lib/gamehall/rollup.jsonl,
# the hall's counts for that day (people, views, bots, referrers, campaigns,
# and the people sent on to each game here). Counts only: no addresses are
# kept, so the trend outlives the self-rotating access log.
# gamehall-rollup.sh [YYYY-MM-DD] (default: yesterday, UTC)
# Cron: /etc/cron.d/gamehall, installed by gamehall/deploy.sh.
set -u
OUT="/var/lib/gamehall/rollup.jsonl"
LOG="/var/log/gamehall/rollup.log"
DAY="${1:-$(date -u -d 'yesterday' +%Y-%m-%d)}"
mkdir -p "$(dirname "$OUT")" "$(dirname "$LOG")"
python3 - "$DAY" "$OUT" <<'PY' >> "$LOG" 2>&1
import datetime, json, os, sys
sys.path.insert(0, "/usr/local/lib/gamehall")
import traffic
day, out = sys.argv[1], sys.argv[2]
t = traffic.scan(day)
row = dict(day=day, people=len(t["addresses"]), views=t["views"], botAddresses=len(t["botAddresses"]),
referrers=dict(t["referrers"]), campaigns=dict(t["campaigns"]), sent=t["sent"],
at=datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"))
rows = [json.loads(l) for l in open(out) if l.strip()] if os.path.exists(out) else []
rows = sorted([r for r in rows if r.get("day") != day] + [row], key=lambda r: r["day"])
with open(out + ".tmp", "w") as fh:
for r in rows:
fh.write(json.dumps(r) + "\n")
os.replace(out + ".tmp", out)
print("%s rolled: %d people, %d views" % (day, row["people"], row["views"]))
PY