89 lines
3.2 KiB
Python
89 lines
3.2 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
|
||
|
|
def extract_energy_teachers():
|
||
|
|
"""从导师信息(通用).json文件中提取能源产业导师"""
|
||
|
|
with open('网页未导入数据/导师信息(通用).json', 'r', encoding='utf-8') as f:
|
||
|
|
data = json.load(f)
|
||
|
|
|
||
|
|
energy_teachers = {}
|
||
|
|
|
||
|
|
for teacher in data:
|
||
|
|
if teacher.get('就业管家') == '能源':
|
||
|
|
name = teacher['查询导师名称']
|
||
|
|
|
||
|
|
# 确定导师类型
|
||
|
|
teacher_type = "复合课导师" # 默认
|
||
|
|
if '公共课' in teacher.get('导师类型', ''):
|
||
|
|
teacher_type = "公共课导师"
|
||
|
|
elif 'AI' in teacher.get('导师类型', ''):
|
||
|
|
teacher_type = "AI课导师"
|
||
|
|
elif 'HR' in teacher.get('导师类型', '') or '企业' in teacher.get('导师类型', ''):
|
||
|
|
teacher_type = "企业资深HR"
|
||
|
|
|
||
|
|
# 获取导师特长或标签
|
||
|
|
specialties = teacher.get('导师特长', teacher.get('导师标签', []))
|
||
|
|
|
||
|
|
energy_teachers[name] = {
|
||
|
|
'name': name,
|
||
|
|
'introduction': teacher['导师介绍'],
|
||
|
|
'specialties': specialties,
|
||
|
|
'avatar': teacher.get('❌导师头像url链接', ''),
|
||
|
|
'type': teacher_type,
|
||
|
|
'verticalDirection': teacher.get('所属垂直方向', ''),
|
||
|
|
'courses': [] # 初始化为空,后续会通过日历数据更新
|
||
|
|
}
|
||
|
|
|
||
|
|
return energy_teachers
|
||
|
|
|
||
|
|
def update_mockdata_teachers():
|
||
|
|
"""更新mockData.js中的teacherData"""
|
||
|
|
|
||
|
|
# 提取能源产业导师
|
||
|
|
energy_teachers = extract_energy_teachers()
|
||
|
|
|
||
|
|
# 读取mockData.js
|
||
|
|
with open('src/data/mockData.js', 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
# 构建新的teacherData对象字符串
|
||
|
|
teacher_data_str = "{\n"
|
||
|
|
for name, teacher in energy_teachers.items():
|
||
|
|
specialties_str = json.dumps(teacher['specialties'], ensure_ascii=False)
|
||
|
|
|
||
|
|
# 转义特殊字符
|
||
|
|
introduction = teacher['introduction'].replace('"', '\\"').replace('\n', '\\n')
|
||
|
|
|
||
|
|
teacher_data_str += f''' "{name}": {{
|
||
|
|
name: "{teacher['name']}",
|
||
|
|
introduction: "{introduction}",
|
||
|
|
specialties: {specialties_str},
|
||
|
|
avatar: "{teacher['avatar']}",
|
||
|
|
type: "{teacher['type']}",
|
||
|
|
verticalDirection: "{teacher['verticalDirection']}",
|
||
|
|
courses: []
|
||
|
|
}},\n'''
|
||
|
|
|
||
|
|
# 移除最后一个逗号
|
||
|
|
teacher_data_str = teacher_data_str.rstrip(',\n') + '\n }'
|
||
|
|
|
||
|
|
# 替换teacherData内容
|
||
|
|
# 找到teacherData的起始位置
|
||
|
|
pattern = r'teacherData:\s*updateTeacherCourses\(\{[\s\S]*?\},\s*allCalendarEvents\)'
|
||
|
|
|
||
|
|
replacement = f'teacherData: updateTeacherCourses({teacher_data_str}, allCalendarEvents)'
|
||
|
|
|
||
|
|
new_content = re.sub(pattern, replacement, content)
|
||
|
|
|
||
|
|
# 写回文件
|
||
|
|
with open('src/data/mockData.js', 'w', encoding='utf-8') as f:
|
||
|
|
f.write(new_content)
|
||
|
|
|
||
|
|
print(f"成功更新 {len(energy_teachers)} 位能源产业导师数据")
|
||
|
|
print("导师名单:", list(energy_teachers.keys()))
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
update_mockdata_teachers()
|