(skill, scene, satisfaction, note='')
| 21 | |
| 22 | |
| 23 | def append_log(skill, scene, satisfaction, note=''): |
| 24 | now = datetime.now() |
| 25 | record = { |
| 26 | 'date': now.strftime('%Y-%m-%d'), |
| 27 | 'weekday': WEEKDAY_MAP[now.weekday()], |
| 28 | 'week': get_week_number(now), |
| 29 | 'skill': skill, |
| 30 | 'scene': scene, |
| 31 | 'satisfaction': int(satisfaction), |
| 32 | 'note': note, |
| 33 | } |
| 34 | |
| 35 | os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True) |
| 36 | |
| 37 | # 如果文件不存在,先写入 schema 行 |
| 38 | if not os.path.exists(LOG_FILE): |
| 39 | schema = { |
| 40 | '_schema': 'skill_usage_log', |
| 41 | '_version': '1.0', |
| 42 | '_description': 'Skill 使用日志。每次使用 Skill 后追加一条记录,用于频率分析和满意度追踪。' |
| 43 | } |
| 44 | with open(LOG_FILE, 'w', encoding='utf-8') as f: |
| 45 | f.write(json.dumps(schema, ensure_ascii=False) + '\n') |
| 46 | |
| 47 | with open(LOG_FILE, 'a', encoding='utf-8') as f: |
| 48 | f.write(json.dumps(record, ensure_ascii=False) + '\n') |
| 49 | |
| 50 | return record |
| 51 | |
| 52 | |
| 53 | def main(): |
no test coverage detected