Files
weval-l99/v131_broken_badge_v2.py
2026-04-24 04:38:58 +02:00

30 lines
1.3 KiB
Python

#!/usr/bin/env python3
import sys
src, dst = sys.argv[1], sys.argv[2]
with open(src, "r", encoding="utf-8") as f:
c = f.read()
if "V131-BROKEN-COUNT" in c:
print("ALREADY", file=sys.stderr)
sys.exit(0)
old = """ if (countEl) countEl.textContent = filtered.length + ' / ' + items.length + ' tuiles' + (pinned.size ? ' (' + pinned.size + ' pin' + (pinned.size>1?'s':'') + ')' : '');"""
new = """ /* V131-BROKEN-COUNT: aggregate status from registry */
const brokenCount = items.filter(e => e.http_status && e.http_status >= 400).length;
if (countEl) {
const brokenSuffix = brokenCount > 0
? ' <span style=\"color:#ef4444;margin-left:6px;font-weight:600\" title=\"Broken dashboards (HTTP &gt;= 400)\">&#9679; ' + brokenCount + ' broken</span>'
: ' <span style=\"color:#10b981;margin-left:6px;font-weight:600\" title=\"All dashboards healthy\">&#9679; all OK</span>';
countEl.innerHTML = filtered.length + ' / ' + items.length + ' tuiles' + (pinned.size ? ' (' + pinned.size + ' pin' + (pinned.size>1?'s':'') + ')' : '') + brokenSuffix;
}"""
if old not in c:
print("anchor missing", file=sys.stderr)
sys.exit(1)
c = c.replace(old, new, 1)
with open(dst, "w", encoding="utf-8") as f:
f.write(c)
print(f"OK size={len(c)}", file=sys.stderr)