From 1003afd6e889568c3b0971b82d01d2305ec4f88d Mon Sep 17 00:00:00 2001 From: Server <10.9.8.204@example.com> Date: Sun, 30 Aug 2026 14:13:17 +0000 Subject: [PATCH] send schedule upload result as file --- bot/admin_schedule.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bot/admin_schedule.py b/bot/admin_schedule.py index c85bb24..996f5d5 100644 --- a/bot/admin_schedule.py +++ b/bot/admin_schedule.py @@ -5,11 +5,12 @@ import json import secrets import tempfile from dataclasses import dataclass +from io import BytesIO from pathlib import Path from typing import Any import requests -from telebot.types import CallbackQuery, Message +from telebot.types import CallbackQuery, InputFile, Message from telebot.util import quick_markup import config @@ -69,12 +70,14 @@ def _clear_database() -> dict[str, Any]: return response.json() -def _format_upload_result(payload: dict[str, Any]) -> str: - serialized = json.dumps(payload, ensure_ascii=False, indent=2) - if len(serialized) > 3400: - serialized = serialized[:3400] + "\n..." - heading = "База применена" if payload.get("ok") else "Архив обработан с ошибками" - return f"{heading}, результат:\n
{html.escape(serialized)}"
+def _send_upload_result(admin_id: int, payload: dict[str, Any]):
+ content = json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8")
+ caption = "База применена" if payload.get("ok") else "Архив обработан с ошибками"
+ return bot.send_document(
+ admin_id,
+ InputFile(BytesIO(content), "schedule-upload-result.json"),
+ caption=caption,
+ )
def _format_request_error(error: requests.RequestException) -> str:
@@ -154,7 +157,7 @@ def upload_schedule_archive(call: CallbackQuery):
PENDING_ARCHIVES.pop(token, None)
archive.path.unlink(missing_ok=True)
clear_schedule_cache()
- return send(call.from_user.id, _format_upload_result(payload))
+ return _send_upload_result(call.from_user.id, payload)
@bot.message_handler(commands=["reset_schedule_db"], func=lambda message: _is_admin(message.from_user.id))