#!/usr/bin/env bash # The hall's visitors: who came in the last hour and today, where from, how # many went on into each game here, and the last week from the rollup. # Runs ON the shared host: gamehall-visitors.sh [YYYY-MM-DD] (default: today, UTC) set -u DAY="${1:-$(date -u +%F)}" python3 - "$DAY" <<'PY' import datetime, json, os, sys sys.path.insert(0, "/usr/local/lib/gamehall") import traffic day = sys.argv[1] now = datetime.datetime.now(datetime.timezone.utc) print("as of %s UTC, day %s" % (now.strftime("%H:%M"), day)) if day == now.strftime("%F"): h = traffic.scan(day, since=now.timestamp() - 3600) print("last hour: %d people, %d page views" % (len(h["addresses"]), h["views"])) t = traffic.scan(day) print("today: %d people, %d page views, %d bot addresses" % (len(t["addresses"]), t["views"], len(t["botAddresses"]))) print("referrers: %s" % (dict(t["referrers"].most_common()) or "none")) print("campaigns: %s" % (dict(t["campaigns"].most_common()) or "none")) print("went on to: %s (Wiz-War is on its own host; its digest shows the hall as a referrer)" % (", ".join("%s %d" % kv for kv in t["sent"].items()))) out = "/var/lib/gamehall/rollup.jsonl" if os.path.exists(out): rows = [json.loads(l) for l in open(out) if l.strip()][-7:] if rows: print("last %d days:" % len(rows)) for r in rows: sent = ", ".join("%s %d" % kv for kv in r.get("sent", {}).items()) print(" %s %3d people %3d views refs %s on to %s" % (r["day"], r["people"], r["views"], r.get("referrers") or "-", sent or "-")) PY