1. 项目概述
这套Python代码是我在探索心理创伤疗愈过程中开发的一系列实用工具。作为一名长期关注心理健康的技术从业者,我发现技术可以成为心理疗愈的有力辅助工具。这套代码包含情绪追踪、正念计时、认知重构练习和资源安全地建立等功能模块,全部采用Python标准库实现,无需额外依赖。
需要模型API调用? 免费领10W Token,多模型网关一键接入 Claude、DeepSeek 等主流模型。
2. 核心功能解析
2.1 情绪日志追踪系统
python复制import datetime
import json
from pathlib import Path
class EmotionTracker:
def __init__(self, data_file="emotion_data.json"):
self.data_file = Path(data_file)
self.ensure_data_file()
def ensure_data_file(self):
if not self.data_file.exists():
with open(self.data_file, 'w') as f:
json.dump([], f)
def record_emotion(self, emotion, intensity, notes=""):
timestamp = datetime.datetime.now().isoformat()
entry = {
"timestamp": timestamp,
"emotion": emotion,
"intensity": intensity,
"notes": notes
}
with open(self.data_file, 'r+') as f:
data = json.load(f)
data.append(entry)
f.seek(0)
json.dump(data,
