#!/usr/bin/env python3
"""
Generate a self-contained HTML file with embedded animation data.
This creates a single HTML file that can be opened directly in any browser
without needing a server or external JSON file (CORS-safe).
"""
from __future__ import annotations
import json
from pathlib import Path
EXAMPLE_DIR = Path(__file__).parent
DATA_FILE = EXAMPLE_DIR / "output" / "animation_data.json"
OUTPUT_FILE = EXAMPLE_DIR / "output" / "interactive_forecast.html"
HTML_TEMPLATE = """
TimesFM Interactive Forecast Animation
TimesFM Forecast Evolution
Watch the forecast evolve as more data is added — forecasts extend to 2025-12
Data Points Used12 / 36
2022-01Using data through 2022-12
Forecast Mean
0.86°C
Forecast Horizon
36 months
Forecast Max
--
Forecast Min
--
All Observed Data
Final Forecast (reference)
Data Used
Current Forecast
80% CI
"""
def main() -> None:
print("=" * 60)
print(" GENERATING SELF-CONTAINED HTML")
print("=" * 60)
# Load animation data
with open(DATA_FILE) as f:
data = json.load(f)
# Generate HTML with embedded data
html_content = HTML_TEMPLATE.format(data_json=json.dumps(data, indent=2))
# Write output
with open(OUTPUT_FILE, "w") as f:
f.write(html_content)
size_kb = OUTPUT_FILE.stat().st_size / 1024
print(f"\n✅ Generated: {OUTPUT_FILE}")
print(f" File size: {size_kb:.1f} KB")
print(f" Fully self-contained — no external dependencies")
if __name__ == "__main__":
main()