68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
|
||
|
|
def safe_update_sutuo_profile():
|
||
|
|
"""
|
||
|
|
安全地更新苏拓的个人档案信息
|
||
|
|
"""
|
||
|
|
|
||
|
|
# 读取能源个人档案数据
|
||
|
|
with open("网页未导入数据/能源产业/能源个人档案.json", 'r', encoding='utf-8') as f:
|
||
|
|
energy_profiles = json.load(f)
|
||
|
|
|
||
|
|
# 查找苏拓的数据
|
||
|
|
sutuo_data = None
|
||
|
|
for profile in energy_profiles:
|
||
|
|
if profile["学员名称"] == "苏拓":
|
||
|
|
sutuo_data = profile
|
||
|
|
break
|
||
|
|
|
||
|
|
if not sutuo_data:
|
||
|
|
print("❌ 未找到苏拓的数据")
|
||
|
|
return
|
||
|
|
|
||
|
|
print(f"✓ 找到苏拓的数据: {sutuo_data}")
|
||
|
|
|
||
|
|
# 读取mockData.js文件
|
||
|
|
with open("src/data/mockData.js", 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
# 创建备份
|
||
|
|
with open("src/data/mockData.js.backup_safe_update", 'w', encoding='utf-8') as f:
|
||
|
|
f.write(content)
|
||
|
|
|
||
|
|
# 安全更新 - 只替换profileOverview中的基本信息
|
||
|
|
updates = [
|
||
|
|
(r'name: "王强"', f'name: "{sutuo_data["学员名称"]}"'),
|
||
|
|
(r'realName: "王强"', f'realName: "{sutuo_data["学员名称"]}"'),
|
||
|
|
(r'studentId: "2325010211"', f'studentId: "{sutuo_data["学号"]}"'),
|
||
|
|
(r'studentNo: "2325010211"', f'studentNo: "{sutuo_data["学号"]}"'),
|
||
|
|
(r'school: "苏州健雄职业技术学院"', f'school: "{sutuo_data["学校名称"]}"'),
|
||
|
|
(r'major: "模具设计与制造"', f'major: "{sutuo_data["专业名称"]}"'),
|
||
|
|
(r'className: "智能制造班"', 'className: "能源班"'),
|
||
|
|
(r'stageName: "自动化设备智能调试"', f'stageName: "{sutuo_data["垂直方向"]}"'),
|
||
|
|
(r'mbti: "ESTJ"', f'mbti: "{sutuo_data["MBTI"]}"'),
|
||
|
|
(r'mbtiType: "ESTJ"', f'mbtiType: "{sutuo_data["MBTI"]}"'),
|
||
|
|
(r'credits: 95', f'credits: {sutuo_data["学分"]}'),
|
||
|
|
(r'classRank: 2', f'classRank: {sutuo_data["班级排名"]}'),
|
||
|
|
]
|
||
|
|
|
||
|
|
# 应用更新
|
||
|
|
updated_content = content
|
||
|
|
for pattern, replacement in updates:
|
||
|
|
old_content = updated_content
|
||
|
|
updated_content = re.sub(pattern, replacement, updated_content, count=1)
|
||
|
|
if old_content != updated_content:
|
||
|
|
print(f"✓ 更新: {pattern} -> {replacement}")
|
||
|
|
|
||
|
|
# 写入更新后的内容
|
||
|
|
with open("src/data/mockData.js", 'w', encoding='utf-8') as f:
|
||
|
|
f.write(updated_content)
|
||
|
|
|
||
|
|
print(f"\n✅ 安全更新苏拓个人档案信息完成")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
safe_update_sutuo_profile()
|