#!/usr/bin/env python3 import os import sys import json import re BASE_DIR = '/data/dashboards/ops' sys.path.insert(0, BASE_DIR) import server print('Generating fresh live telemetry snapshot...') snapshot = server.get_system_telemetry(force_refresh=True) snap_str = json.dumps(snapshot, ensure_ascii=False) print(f'Snapshot ready: {len(snapshot.get("dashboards", []))} dashboards, {len(snapshot.get("team_pulse", []))} team members.') index_path = os.path.join(BASE_DIR, 'index.html') new_path = os.path.join(BASE_DIR, 'new', 'index.html') for p in [index_path, new_path]: if not os.path.exists(p): continue print(f'Patching {p}...') with open(p, 'r', encoding='utf-8') as f: html = f.read() # 1. Replace window.__INITIAL_DATA__ html = re.sub( r'window\.__INITIAL_DATA__\s*=\s*\{[\s\S]*?\};\s*renderTeam', 'window.__INITIAL_DATA__ = ' + snap_str + ';\n renderTeam', html, count=1 ) # 2. Update USER_LABELS old_labels = r'''const USER_LABELS = \{[\s\S]*?\};''' new_labels = '''const USER_LABELS = { 'hamed': { name: 'حامد فلاحی', avatar: '👑' }, 'mohadese': { name: 'محدثه معصومی', avatar: '⚖️' }, 'ehsan': { name: 'احسان اسدیان', avatar: '⚙️' }, 'iman': { name: 'ایمان', avatar: '💰' }, 'ghazale': { name: 'غزاله مددی', avatar: '🎯' }, 'dara': { name: 'دارا', avatar: '📈' }, 'sara': { name: 'سارا', avatar: '🎬' }, 'parastoo': { name: 'پرستو', avatar: '📱' }, 'elahe': { name: 'الهه فلاحی', avatar: '📊' }, 'saleh': { name: 'صالح اسکندرزاده', avatar: '🤝' }, 'kimya': { name: 'کیمیا', avatar: '🔬' } };''' html = re.sub(old_labels, new_labels, html, count=1) # 3. Update owner filter buttons if missing kimya if "filterByOwner('kimya')" not in html: if "filterByOwner('dara')" in html: html = html.replace( '''''', ''' ''' ) elif "filterByOwner('hamed')" in html: html = html.replace( '''''', ''' ''' ) # 4. Update counts in text for old_cnt in ['25 سامانه', '28 سامانه', '۲۵ سامانه', '۲۸ سامانه']: html = html.replace(old_cnt, '۳۱ سامانه') for old_team in ['۸ عضو تیم', '۱۰ عضو تیم و مدیران', '8 عضو تیم', '10 عضو تیم و مدیران', '۱۰ عضو تیم']: html = html.replace(old_team, '۱۱ عضو تیم و مدیران') with open(p, 'w', encoding='utf-8') as f: f.write(html) print(f'Successfully updated {p}') print('HTML files patched cleanly.')