"""Добавляет /notify в do_POST.""" import ast P = "/opt/hub-core/core.py" s = open(P, encoding="utf-8").read() if s.count('"/notify"') >= 2 or s.count("startswith(\"/notify\")") >= 2: print("уже есть в обоих") raise SystemExit(0) route = ''' if self.path.startswith("/notify"): try: ln = int(self.headers.get("Content-Length") or 0) raw = self.rfile.read(ln) if ln else b"{}" data = json.loads(raw or b"{}") except Exception: data = {} title = (data.get("title") or data.get("name") or "Событие").strip() msg = (data.get("message") or data.get("msg") or "").strip() ok = _matrix_notify("🔔 " + title + (("\\n" + msg) if msg else "")) return self._json(200 if ok else 502, {"sent": bool(ok)}) ''' start = s.find(" def do_POST(self):") if start < 0: print("нет do_POST") raise SystemExit(1) anchor = ' if self.path.startswith("/event"):' i = s.find(anchor, start) if i < 0: print("нет /event в do_POST") raise SystemExit(1) s = s[:i] + route + s[i:] open(P, "w", encoding="utf-8").write(s) ast.parse(s) print("core.py: /notify добавлен в do_POST")