"""Builds the neon 'hacker' sidebar: MOST TRACKED + AIRPORT DISRUPTIONS panels. Mirrors the FlightRadar24 sidebar layout. Since the FR24 API exposes neither viewer/tracker counts nor an airport-disruption feed, both panels are derived from the live in-view flights (and real weather from Open-Meteo). Labels make the derivation explicit so nothing is presented as official FR24 data. """ from __future__ import annotations from collections import Counter import fr24 import weather _AIRPORT_NAMES = { "EGLL": "London", "KJFK": "New York", "OMDB": "Dubai", "EGBB": "Birmingham", "ZGSZ": "Shenzhen", "KDFW": "Dallas", "LTBJ": "Izmir", "EHAM": "Amsterdam", "LFPG": "Paris", "EDDF": "Frankfurt", "RJTT": "Tokyo", "VHHH": "Hong Kong", } def _fmt_int(n) -> str: try: return f"{int(n):,}" except Exception: return "—" def _esc(s) -> str: return (str(s).replace("&", "&").replace("<", "<").replace(">", ">") if s is not None else "") def _most_tracked(flights, limit=8): ranked = sorted( [f for f in flights if f.get("gspeed")], key=lambda f: f.get("gspeed") or 0, reverse=True, )[:limit] rows = [] for i, f in enumerate(ranked, 1): cs = _esc(f.get("callsign") or f.get("flight") or "N/A") typ = _esc(f.get("type") or "—") orig = _esc(f.get("orig") or "N/A") dest = _esc(f.get("dest") or "N/A") rows.append(f"""