""" Generates a self-contained HTML order form from the latest scraped menu. The form shows this week's meals with quantity selectors, a running total, and submits orders to the backend (local Flask or cloud API Gateway). Usage: python3 generate_form.py # local mode python3 generate_form.py --api-url URL --google-client-id ID # cloud mode """ import argparse import json import sys from datetime import datetime from pathlib import Path from jinja2 import Environment, FileSystemLoader, select_autoescape PROJECT_ROOT = Path(__file__).resolve().parents[2] OUTPUT_DIR = PROJECT_ROOT / "output" CONFIG_PATH = PROJECT_ROOT / "config.json" TEMPLATES_DIR = Path(__file__).resolve().parent / "templates" def load_config(): with open(CONFIG_PATH) as f: return json.load(f) def latest_menu() -> dict: files = sorted(OUTPUT_DIR.glob("menu-*.json"), reverse=True) if not files: print("Error: No menu JSON found. Run scrape_menu.py first.", file=sys.stderr) sys.exit(1) with open(files[0]) as f: return json.load(f) def _json_for_script(value) -> str: """Serialize for embedding in a