104 lines
4.5 KiB
Python
104 lines
4.5 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def update_profile_with_sutuo_data():
|
|||
|
|
"""
|
|||
|
|
使用能源个人档案.json中苏拓的数据更新profileOverview
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 读取能源个人档案数据
|
|||
|
|
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_before_sutuo_update", 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
# 能源头像映射(使用现有的头像列表)
|
|||
|
|
energy_avatars = {
|
|||
|
|
"苏拓": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/02393125baa474d558c484c0677664b1.jpg",
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 构建替换模式和新数据
|
|||
|
|
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'avatar: "https://ddcz-1315997005\.cos\.ap-nanjing\.myqcloud\.com/static/avatar/douyin/152361c6c68a193660cdbdf9074c2cf3\.jpg"': f'avatar: "{energy_avatars.get(sutuo_data["学员名称"], "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/02393125baa474d558c484c0677664b1.jpg")}"',
|
|||
|
|
r'school: "苏州健雄职业技术学院"': f'school: "{sutuo_data["学校名称"]}"',
|
|||
|
|
r'major: "模具设计与制造"': f'major: "{sutuo_data["专业名称"]}"',
|
|||
|
|
r'className: "智能制造班"': 'className: "能源班"',
|
|||
|
|
r'grade: "2023级"': 'grade: "2023级"',
|
|||
|
|
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["班级排名"]}',
|
|||
|
|
r'rank: 2': f'rank: {sutuo_data["班级排名"]}',
|
|||
|
|
r'score: 95': f'score: {sutuo_data["学分"]}',
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 应用替换
|
|||
|
|
updated_content = content
|
|||
|
|
for pattern, replacement in updates.items():
|
|||
|
|
old_content = updated_content
|
|||
|
|
updated_content = re.sub(pattern, replacement, updated_content)
|
|||
|
|
if old_content != updated_content:
|
|||
|
|
print(f"✓ 更新: {pattern} -> {replacement}")
|
|||
|
|
|
|||
|
|
# 更新ranking数组中的个人信息(isMe: true的那一项)
|
|||
|
|
sutuo_ranking_data = f'''{{
|
|||
|
|
rank: {sutuo_data["班级排名"]},
|
|||
|
|
studentId: "{sutuo_data["学号"]}",
|
|||
|
|
studentName: "{sutuo_data["学员名称"]}",
|
|||
|
|
name: "{sutuo_data["学员名称"]}",
|
|||
|
|
avatar: "{energy_avatars.get(sutuo_data["学员名称"], "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/02393125baa474d558c484c0677664b1.jpg")}",
|
|||
|
|
score: {sutuo_data["学分"]},
|
|||
|
|
credits: {sutuo_data["学分"]},
|
|||
|
|
school: "{sutuo_data["学校名称"]}",
|
|||
|
|
major: "{sutuo_data["专业名称"]}",
|
|||
|
|
isMe: true,
|
|||
|
|
}}'''
|
|||
|
|
|
|||
|
|
# 替换ranking数组中的个人信息项
|
|||
|
|
ranking_pattern = r'\{\s*rank: 2,\s*studentId: "2325010211",[\s\S]*?isMe: true,\s*\}'
|
|||
|
|
updated_content = re.sub(ranking_pattern, sutuo_ranking_data, updated_content)
|
|||
|
|
|
|||
|
|
# 写入更新后的内容
|
|||
|
|
with open("src/data/mockData.js", 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(updated_content)
|
|||
|
|
|
|||
|
|
print(f"\n✅ 成功使用苏拓的数据更新个人档案信息")
|
|||
|
|
print(f"📋 更新内容:")
|
|||
|
|
print(f" - 姓名: {sutuo_data['学员名称']}")
|
|||
|
|
print(f" - 学号: {sutuo_data['学号']}")
|
|||
|
|
print(f" - 学校: {sutuo_data['学校名称']}")
|
|||
|
|
print(f" - 专业: {sutuo_data['专业名称']}")
|
|||
|
|
print(f" - 垂直方向: {sutuo_data['垂直方向']}")
|
|||
|
|
print(f" - MBTI: {sutuo_data['MBTI']}")
|
|||
|
|
print(f" - 学分: {sutuo_data['学分']}")
|
|||
|
|
print(f" - 班级排名: {sutuo_data['班级排名']}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
update_profile_with_sutuo_data()
|