paradramorama/tools/cardgen/add_tile.py
m3ultra 480e551552 Add the arcade-tile installer used to list PARADRAMORAMA
Inserts the tile at the front of the arcade grid with a 'new' badge,
matching sibling markup exactly, and recomputes the footer count from
the live tile list rather than trusting the hand-maintained number.
Refuses to run twice so a re-run cannot duplicate the tile.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 22:41:20 +10:00

38 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Insert the PARADRAMORAMA tile into the monsterrobot.games arcade grid.
Front of the arcade grid (newest first) with a 'new' badge, matching the
markup of every sibling tile exactly. Also bumps the footer game count.
"""
import re, sys
SRC = sys.argv[1]
DST = sys.argv[2]
html = open(SRC, encoding='utf-8').read()
TILE = ('<a class="tile" href="/paradramorama/"><div class="art">'
'<img class="a" loading="lazy" src="covers/paradramorama.jpg" alt="">'
'<img class="b" loading="lazy" src="covers/paradramorama_riso.jpg" alt="">'
'<span class="badge">new</span></div>'
'<div class="cap"><span class="t">Paradramorama</span>'
'<span class="go">▶ play</span></div></a>')
if 'paradramorama' in html.lower():
sys.exit('already present — refusing to add a duplicate tile')
# the arcade grid opens with <div class="grid arc"> ; insert as its first child
anchor = '<div class="grid arc">'
if anchor not in html:
sys.exit('could not find the arcade grid')
html = html.replace(anchor, anchor + TILE, 1)
# footer count
m = re.search(r'(\d+) games and counting', html)
if m:
n = int(m.group(1)) + 1
html = html.replace(m.group(0), f'{n} games and counting', 1)
print(f'footer count {m.group(1)} -> {n}')
open(DST, 'w', encoding='utf-8').write(html)
print(f'tile inserted, {len(html)} bytes')