with open('templates/dashboard.html', 'r', encoding='utf-8') as f: text = f.read() # Make EVERYTHING single brackets first! text = text.replace('{{', '{').replace('}}', '}') # Make python variables back into double brackets for Jinja python_vars = [ 'stroke_offset', 'success_pct', 'total_applied', 'BOT_PAUSED', 'gemini_key_count', 'active_key_num', 'qa_size', 'active_chat_id', 'len(TARGET_CHANNELS)', 'channels_html', 'recent_jobs_html', 'HANDOFF_URL', 'total_skipped', "stats.get('applied', 0)", "stats.get('current_streak', 0)", "len(applied)", "stats.get('skipped', 0)", 'gemini_status', 'groq_status', 'os.path.exists(RESUME_FILE)', 'imap_status', 'ghost_mode_active', 'TARGET_CHANNEL' ] for var in python_vars: # Handle {var} text = text.replace('{' + var + '}', '{{' + var + '}}') # Handle {var|safe} text = text.replace('{' + var + '|safe}', '{{' + var + '|safe}}') # Replace the specific lines that use inline python logic. fixes = [ ("{ 'bg-green-500/15 text-green-400 border border-green-500/30' if not BOT_PAUSED else 'bg-yellow-500/15 text-yellow-400 border border-yellow-500/30' }", "{{ 'bg-green-500/15 text-green-400 border border-green-500/30' if not BOT_PAUSED else 'bg-yellow-500/15 text-yellow-400 border border-yellow-500/30' }}"), ("{ 'bg-green-400 animate-pulse' if not BOT_PAUSED else 'bg-yellow-400' }", "{{ 'bg-green-400 animate-pulse' if not BOT_PAUSED else 'bg-yellow-400' }}"), ("{ '▶️ RUNNING' if not BOT_PAUSED else '⏸️ PAUSED' }", "{{ '▶️ RUNNING' if not BOT_PAUSED else '⏸️ PAUSED' }}"), ("{'rgba(34,197,94,0.15)' if not BOT_PAUSED else 'rgba(245,158,11,0.15)'}", "{{'rgba(34,197,94,0.15)' if not BOT_PAUSED else 'rgba(245,158,11,0.15)'}}"), ("{'rgba(34,197,94,0.4)' if not BOT_PAUSED else 'rgba(245,158,11,0.4)'}", "{{'rgba(34,197,94,0.4)' if not BOT_PAUSED else 'rgba(245,158,11,0.4)'}}"), ("{'#4ade80' if not BOT_PAUSED else '#fbbf24'}", "{{'#4ade80' if not BOT_PAUSED else '#fbbf24'}}"), ("{'ai-online' if gemini_status == 'ONLINE' else 'ai-offline'}", "{{'ai-online' if gemini_status == 'ONLINE' else 'ai-offline'}}"), ("{'text-green-400' if gemini_status == 'ONLINE' else 'text-red-400'}", "{{'text-green-400' if gemini_status == 'ONLINE' else 'text-red-400'}}"), ("{'ai-online' if groq_status == 'ONLINE' else 'ai-offline'}", "{{'ai-online' if groq_status == 'ONLINE' else 'ai-offline'}}"), ("{'text-green-400' if groq_status == 'ONLINE' else 'text-red-400'}", "{{'text-green-400' if groq_status == 'ONLINE' else 'text-red-400'}}"), ("{'text-green-400' if os.path.exists(RESUME_FILE) else 'text-red-400'}", "{{'text-green-400' if os.path.exists(RESUME_FILE) else 'text-red-400'}}"), ("{'LOADED' if os.path.exists(RESUME_FILE) else 'MISSING'}", "{{'LOADED' if os.path.exists(RESUME_FILE) else 'MISSING'}}"), ("{'text-green-400 drop-shadow-[0_0_8px_rgba(74,222,128,0.5)]' if imap_status == 'CONNECTED' else 'text-gray-500'}", "{{'text-green-400 drop-shadow-[0_0_8px_rgba(74,222,128,0.5)]' if imap_status == 'CONNECTED' else 'text-gray-500'}}"), ("{'text-fuchsia-400 drop-shadow-[0_0_8px_rgba(232,121,249,0.5)]' if ghost_mode_active else 'text-gray-500'}", "{{'text-fuchsia-400 drop-shadow-[0_0_8px_rgba(232,121,249,0.5)]' if ghost_mode_active else 'text-gray-500'}}"), ("{'STREAMING' if ghost_mode_active else 'STANDBY'}", "{{'STREAMING' if ghost_mode_active else 'STANDBY'}}"), ("{'⏸ PAUSED' if BOT_PAUSED else '▶ RUNNING'}", "{{'⏸ PAUSED' if BOT_PAUSED else '▶ RUNNING'}}") ] for old, new in fixes: text = text.replace(old, new) with open('templates/dashboard.html', 'w', encoding='utf-8') as f: f.write(text) print('Dashboard template correctly fixed')