#!/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 = (''
'

'
'

'
'
new '
'Paradramorama'
'▶ play
')
if 'paradramorama' in html.lower():
sys.exit('already present — refusing to add a duplicate tile')
# the arcade grid opens with
; insert as its first child
anchor = '
'
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')