#!/usr/bin/env bash
set -euo pipefail
python3 - <<'PY'
import json, re, urllib.request, collections
html=urllib.request.urlopen('http://127.0.0.1:9130/').read().decode()
m=re.search(r'__HERMES_SESSION_TOKEN__="([^"]+)"', html)
req=urllib.request.Request('http://127.0.0.1:9130/api/plugins/kanban/board')
if m: req.add_header('Authorization', 'Bearer '+m.group(1))
d=json.load(urllib.request.urlopen(req))
print('columns', [c.get('name') for c in d.get('columns',[])])
tasks=[t for c in d.get('columns',[]) for t in c.get('tasks',[])]
print('total', len(tasks))
print('api_statuses', dict(collections.Counter(t.get('status') for t in tasks)))
print('column_counts', {c.get('name'):len(c.get('tasks',[])) for c in d.get('columns',[])})
print('missing_status', sum(1 for t in tasks if not t.get('status')))
PY