Embed Chart.js inline — report is now fully self-contained
No internet connection required to open dc_md_va_unemployment_report.html. chart.umd.min.js (200 KB) is bundled into the HTML at generation time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -6,9 +6,12 @@ Output: dc_md_va_unemployment_report.html (open in any browser)
|
||||
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from config import BLS_API_KEY, BLS_API_BASE
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Series config (same as dashboard script)
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -237,7 +240,7 @@ HTML_TEMPLATE = """<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DC / MD / VA Unemployment Report — {report_date}</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
|
||||
<script>{chartjs}</script>
|
||||
<style>
|
||||
*, *::before, *::after {{ box-sizing: border-box; }}
|
||||
body {{
|
||||
@ -382,6 +385,10 @@ def main():
|
||||
|
||||
report_date = datetime.now().strftime("%B %d, %Y")
|
||||
|
||||
chartjs_path = os.path.join(SCRIPT_DIR, "chart.umd.min.js")
|
||||
with open(chartjs_path) as f:
|
||||
chartjs = f.read()
|
||||
|
||||
labels, datasets = build_rate_chart_data(results, months=24)
|
||||
rate_chart_json = json.dumps({"labels": labels, "datasets": datasets})
|
||||
|
||||
@ -390,6 +397,7 @@ def main():
|
||||
cards=build_cards(results),
|
||||
summary_table=build_summary_table(results),
|
||||
rate_chart_json=rate_chart_json,
|
||||
chartjs=chartjs,
|
||||
)
|
||||
|
||||
out = "dc_md_va_unemployment_report.html"
|
||||
|
||||
Reference in New Issue
Block a user