From e29bdacb3eef6d7817ccb0c158d07164b82feb70 Mon Sep 17 00:00:00 2001 From: pilot <657434@03b.ru> Date: Mon, 10 Aug 2026 14:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=20=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=20user=5Flogger.py:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=B0=D0=BF=D0=BA=D0=B8=20=D0=B8=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B8=20=D0=B2=20=D0=BB=D0=BE=D0=B3,=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B3=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=BB=D0=B8=D1=81=D1=8C,=20=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B2?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C.=20=20=D0=92=20bo?= =?UTF-8?q?t=5Fpromo=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=B2=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D0=BE=D0=BB=D1=8C=20=D1=81=D1=84=D0=BE=D1=80=D0=BC=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D1=81?= =?UTF-8?q?=D1=8B=D0=BB=D0=BE=D0=BA=20(=D1=81=D1=82=D0=B0=D1=82=D1=83?= =?UTF-8?q?=D1=81-=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B0=20=D0=B8=20QR-?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BA=D0=B0)=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8.=20?= =?UTF-8?q?=D0=A2=D0=B0=D0=BA=D0=B6=D0=B5=20=D1=83=D0=BB=D1=83=D1=87=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B7=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restoran_max_bot/promo_handlers.py | 4 ++ .../restoran_max_bot/user_logger.py | 59 +++++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/restoran_max_bot/restoran_max_bot/promo_handlers.py b/restoran_max_bot/restoran_max_bot/promo_handlers.py index ebe7f8f..1a5cd79 100644 --- a/restoran_max_bot/restoran_max_bot/promo_handlers.py +++ b/restoran_max_bot/restoran_max_bot/promo_handlers.py @@ -71,6 +71,10 @@ def bot_promo(client: Client, message: dict, settings_max: dict) -> bool: img.save(f"{STATICFILES_DIRS[0]}/client_qr/{file_name}") qr_url = f"{BASE_URL}/static/client_qr/{file_name}" + # Выводим ссылки в консоль для отладки + print(f"🔍 PROMO DEBUG: статус-ссылка = {url_promo}") + print(f"🔍 PROMO DEBUG: QR-картинка = {qr_url}") + # Логируем сформированные ссылки log_user_action( client=client, diff --git a/restoran_max_bot/restoran_max_bot/user_logger.py b/restoran_max_bot/restoran_max_bot/user_logger.py index 5a972b9..ac02546 100644 --- a/restoran_max_bot/restoran_max_bot/user_logger.py +++ b/restoran_max_bot/restoran_max_bot/user_logger.py @@ -7,7 +7,11 @@ from max_bot.models import Client # Папка для логов активности пользователей LOG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'log', 'user_activity') -os.makedirs(LOG_DIR, exist_ok=True) + +try: + os.makedirs(LOG_DIR, exist_ok=True) +except Exception as e: + print(f"⚠️ Ошибка создания папки для логов: {e}") _lock = Lock() @@ -26,30 +30,33 @@ def log_user_action( Логирует действие пользователя в структурированном JSON-формате. Запись добавляется в файл user_activity_YYYY-MM-DD.log. """ - timestamp = datetime.now().isoformat() - log_entry = { - "timestamp": timestamp, - "client_id": client.id, - "chat_id": chat_id, - "action_type": action_type, - "details": details or {}, - } - if user_query is not None: - log_entry["user_query"] = user_query - if intent is not None: - log_entry["intent"] = intent - if entities is not None: - log_entry["entities"] = entities - if response is not None: - log_entry["response"] = response - if command is not None: - log_entry["command"] = command + try: + timestamp = datetime.now().isoformat() + log_entry = { + "timestamp": timestamp, + "client_id": client.id, + "chat_id": chat_id, + "action_type": action_type, + "details": details or {}, + } + if user_query is not None: + log_entry["user_query"] = user_query + if intent is not None: + log_entry["intent"] = intent + if entities is not None: + log_entry["entities"] = entities + if response is not None: + log_entry["response"] = response + if command is not None: + log_entry["command"] = command - # Определяем имя файла по дате - date_str = datetime.now().strftime("%Y-%m-%d") - log_file = os.path.join(LOG_DIR, f"user_activity_{date_str}.log") + # Определяем имя файла по дате + date_str = datetime.now().strftime("%Y-%m-%d") + log_file = os.path.join(LOG_DIR, f"user_activity_{date_str}.log") - # Потокобезопасная запись - with _lock: - with open(log_file, 'a', encoding='utf-8') as f: - f.write(json.dumps(log_entry, ensure_ascii=False) + '\n') + # Потокобезопасная запись + with _lock: + with open(log_file, 'a', encoding='utf-8') as f: + f.write(json.dumps(log_entry, ensure_ascii=False) + '\n') + except Exception as e: + print(f"⚠️ Ошибка записи лога: {e}")