fix(heartFC_Cycleinfo): 修复文件路径处理并添加调试日志
- 修复目录路径拼接问题,确保文件写入到正确路径 - 添加调试日志打印目录名和最终文件路径,便于问题排查
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user