"""Учебный расчёт и уведомление. HTTP выключен по умолчанию.""" import json import os import urllib.request def send_event(title, meta): payload = {"event": title, "meta": meta} if os.environ.get("ONTIK_DRY_RUN", "1") == "1": print(json.dumps(payload, ensure_ascii=False, indent=2)) return base = os.environ.get("ONTIK_BASE_URL", "https://app.ontik.ru").rstrip("/") body = json.dumps(payload, ensure_ascii=False).encode("utf-8") request = urllib.request.Request(base + "/v1/events", data=body, headers={ "Content-Type": "application/json", "X-Ontik-Key": os.environ["ONTIK_API_KEY"], }) with urllib.request.urlopen(request, timeout=10) as response: print("Ontik:", response.status) def build_report(): # Здесь будет ваша задача; сейчас это учебный расчёт. return {"rows": 120, "result": "completed"} if __name__ == "__main__": try: result = build_report() except Exception as task_error: try: send_event("Ошибка подготовки отчёта", {"error_type": type(task_error).__name__}) except Exception as notification_error: print("Ошибка уведомления:", type(notification_error).__name__) raise else: try: send_event("Отчёт подготовлен", result) except Exception as notification_error: print("Задача выполнена, уведомление не отправлено:", type(notification_error).__name__)