Files
online_sys/frontend_大健康/replace_profile_data.py

67 lines
2.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 读取mockData.js文件
with open('src/data/mockData.js', 'r', encoding='utf-8') as f:
content = f.read()
# 何泽谦的个人信息
new_profile_data = '''// 个人档案详细信息
profile: {
name: "何泽谦",
gender: "",
studentId: "2325070573",
avatar: "https://p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/3ee5f13fb09879ecb5185e440cef6eb9.png~tplv-uwbnlip3yd-webp.webp",
school: "苏州农业职业技术学院",
major: "药品生产技术",
courses: ["复合能力培养", "健康管理", "药品工艺", "质量保障体系"],
className: "大健康",
studyPhase: "复合能力培养",
badges: {
credits: 94,
classRank: 7,
mbti: "ESTJ",
},
// MBTI测评报告详细数据
mbtiReport: {
type: "ESTJ",
title: "总经理 (Executive)",'''
# 找到profile的开始位置
start_marker = "// 个人档案详细信息\n profile: {"
start_pos = content.find(start_marker)
if start_pos == -1:
print("❌ 找不到profile数据标记")
exit(1)
# 找到mbtiReport的开始位置
mbti_marker = "// MBTI测评报告详细数据\n mbtiReport: {\n type:"
mbti_pos = content.find(mbti_marker, start_pos)
# 找到title行的结束位置
title_end_marker = 'title: "'
title_pos = content.find(title_end_marker, mbti_pos)
if title_pos != -1:
# 找到这一行的结束
line_end = content.find(',\n', title_pos)
if line_end != -1:
# 替换内容
new_content = content[:start_pos] + new_profile_data + content[line_end + 1:]
# 写回文件
with open('src/data/mockData.js', 'w', encoding='utf-8') as f:
f.write(new_content)
print("✅ 成功替换profile数据为何泽谦的信息")
print(" - 姓名:何泽谦")
print(" - 学号2325070573")
print(" - 学校:苏州农业职业技术学院")
print(" - 专业:药品生产技术")
print(" - 学分94")
print(" - 班级排名7")
print(" - MBTIESTJ")
else:
print("❌ 找不到title行的结束位置")
else:
print("❌ 找不到title标记")