From d0f3747292e242b1b3ef5c14125a6648877c3ff0 Mon Sep 17 00:00:00 2001 From: zhiyucn Date: Sun, 1 Jun 2025 19:24:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(heartFC=5FCycleinfo):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复目录路径拼接问题,确保文件写入到正确路径 - 添加调试日志打印目录名和最终文件路径,便于问题排查 --- src/chat/focus_chat/heartFC_Cycleinfo.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chat/focus_chat/heartFC_Cycleinfo.py b/src/chat/focus_chat/heartFC_Cycleinfo.py index 1fb932035..a12dc861f 100644 --- a/src/chat/focus_chat/heartFC_Cycleinfo.py +++ b/src/chat/focus_chat/heartFC_Cycleinfo.py @@ -95,17 +95,20 @@ class CycleDetail: def log_cycle_to_file(self, file_path: str): """将循环信息写入文件""" - # 如果目录不存在,则创建目录 + # 如果目录不存在,则创建目 dir_name = os.path.dirname(file_path) # 去除特殊字符,保留字母、数字、下划线、中划线和中文 dir_name = "".join( char for char in dir_name if char.isalnum() or char in ["_", "-", "/"] or "\u4e00" <= char <= "\u9fff" ) + print("dir_name:", dir_name) if dir_name and not os.path.exists(dir_name): os.makedirs(dir_name, exist_ok=True) # 写入文件 import json + file_path = os.path.join(dir_name, os.path.basename(file_path)) + print("file_path:", file_path) with open(file_path, "a", encoding="utf-8") as f: f.write(json.dumps(self.to_dict(), ensure_ascii=False) + "\n")