#!/usr/bin/env python3 import sys import json import os CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) PARENT_DIR = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir)) if CURRENT_DIR not in sys.path: sys.path.append(CURRENT_DIR) if PARENT_DIR not in sys.path: sys.path.append(PARENT_DIR) from common import load_articles, write_result # noqa: E402 def main(): try: payload = json.load(sys.stdin) except Exception as exc: # noqa: BLE001 print(f"Failed to read JSON: {exc}", file=sys.stderr) sys.exit(1) content_dir = payload.get("contentDir") or "content" output_path = payload.get("outputPath") public_path = payload.get("publicPath") articles = load_articles(content_dir) temps = [] hums = [] presses = [] for article in articles: weather = article.get("weather") or {} try: t = float(weather.get("temperature")) h = float(weather.get("humidity")) except Exception: continue temps.append(t) hums.append(h) try: p = float(weather.get("pressure")) presses.append(p) except Exception: presses.append(None) # Align pressures length if all(p is None for p in presses): presses = [] else: presses = [p for p in presses if p is not None] try: from render_stats_charts import render_weather_hexbin, setup_rcparams except ImportError as exc: # noqa: BLE001 print(f"Failed to import renderer: {exc}", file=sys.stderr) sys.exit(1) setup_rcparams() render_weather_hexbin( { "temps": temps, "hums": hums, "presses": presses if len(presses) == len(temps) else [], "title": "Conditions météo à la publication", }, output_path, ) write_result({"image": public_path, "meta": {"points": len(temps)}}) if __name__ == "__main__": main()