"""Serve the tunie viewer locally so the catalogue dropdown can fetch cached maps. python3 serve.py # serves this folder at http://localhost:8000 python3 serve.py 9000 # custom port Browsers block fetch() on file:// URLs, so the Triumph-tables catalogue dropdown only works when the viewer is served over HTTP. Drag-and-drop works either way. Run download_maps.py first to populate maps_cache/. """ from __future__ import annotations import http.server import socketserver import sys import webbrowser from pathlib import Path HERE = Path(__file__).parent def main() -> int: port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000 if not (HERE / "maps_cache" / "index.json").exists(): print("note: maps_cache/index.json not found — run download_maps.py first " "for the catalogue dropdown (drag-and-drop still works).") handler = lambda *a, **k: http.server.SimpleHTTPRequestHandler(*a, directory=str(HERE), **k) with socketserver.TCPServer(("127.0.0.1", port), handler) as httpd: url = f"http://localhost:{port}/tunie-viewer.html" print(f"serving {HERE} at {url}\nCtrl-C to stop.") try: webbrowser.open(url) except Exception: pass try: httpd.serve_forever() except KeyboardInterrupt: print("\nstopped.") return 0 if __name__ == "__main__": raise SystemExit(main())