123 lines
3.8 KiB
Python
123 lines
3.8 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import os
|
||
|
|
import datetime
|
||
|
|
import shutil
|
||
|
|
import json
|
||
|
|
from collections import defaultdict
|
||
|
|
|
||
|
|
def generate_industries_with_avatars():
|
||
|
|
"""
|
||
|
|
生成带有岗位头像的industries数据
|
||
|
|
"""
|
||
|
|
# 读取能源岗位简历数据
|
||
|
|
with open("网页未导入数据/能源产业/能源岗位简历.json", 'r', encoding='utf-8') as f:
|
||
|
|
energy_jobs = json.load(f)
|
||
|
|
|
||
|
|
# 读取岗位等级数据(包含头像)
|
||
|
|
with open("src/data/joblevel.json", 'r', encoding='utf-8') as f:
|
||
|
|
joblevel_data = json.load(f)
|
||
|
|
|
||
|
|
# 创建岗位名称到头像的映射
|
||
|
|
position_avatars = {}
|
||
|
|
for level_key, level_data in joblevel_data["data"].items():
|
||
|
|
for position in level_data["list"]:
|
||
|
|
position_avatars[position["position_name"]] = position.get("img", "")
|
||
|
|
|
||
|
|
# 按岗位群分组
|
||
|
|
job_groups = defaultdict(list)
|
||
|
|
for job in energy_jobs:
|
||
|
|
group_name = job.get("简历岗位群", "")
|
||
|
|
if group_name:
|
||
|
|
job_groups[group_name].append(job)
|
||
|
|
|
||
|
|
# 生成industries数据结构
|
||
|
|
industries = []
|
||
|
|
group_id = 1
|
||
|
|
|
||
|
|
for group_name, jobs in job_groups.items():
|
||
|
|
industry = {
|
||
|
|
"id": f"energy_{group_id}",
|
||
|
|
"name": group_name,
|
||
|
|
"positions": [],
|
||
|
|
"questions": [
|
||
|
|
{
|
||
|
|
"id": f"group_q{group_id}",
|
||
|
|
"question": f"# {group_name}面试题",
|
||
|
|
"subQuestions": []
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
# 添加该岗位群下的所有岗位
|
||
|
|
pos_id = 1
|
||
|
|
for job in jobs:
|
||
|
|
position_name = job["岗位名称"]
|
||
|
|
avatar_url = position_avatars.get(position_name, "")
|
||
|
|
|
||
|
|
position = {
|
||
|
|
"id": f"energy_{group_id}_{pos_id}",
|
||
|
|
"title": position_name,
|
||
|
|
"level": job.get("岗位等级标签", "基础岗"),
|
||
|
|
"avatar": avatar_url,
|
||
|
|
"department": group_name,
|
||
|
|
"type": "全职",
|
||
|
|
"experience": "1-3年",
|
||
|
|
"education": "大专",
|
||
|
|
"salary": "8-15K",
|
||
|
|
"location": "北京",
|
||
|
|
"updateTime": "2024-01-20",
|
||
|
|
"description": f"负责{position_name}相关工作",
|
||
|
|
"requirements": []
|
||
|
|
}
|
||
|
|
industry["positions"].append(position)
|
||
|
|
pos_id += 1
|
||
|
|
|
||
|
|
industries.append(industry)
|
||
|
|
group_id += 1
|
||
|
|
|
||
|
|
return industries
|
||
|
|
|
||
|
|
def replace_industries_in_mock():
|
||
|
|
"""
|
||
|
|
替换mock文件中的industries数据
|
||
|
|
"""
|
||
|
|
mock_file = "src/mocks/resumeInterviewMock.js"
|
||
|
|
|
||
|
|
# 备份文件
|
||
|
|
backup_path = f"{mock_file}.backup_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
||
|
|
shutil.copy(mock_file, backup_path)
|
||
|
|
print(f"✅ 已备份文件到:{backup_path}")
|
||
|
|
|
||
|
|
# 生成新的industries数据
|
||
|
|
industries = generate_industries_with_avatars()
|
||
|
|
|
||
|
|
# 读取原文件内容
|
||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
# 查找industries数组的起始和结束位置
|
||
|
|
import re
|
||
|
|
|
||
|
|
# 生成新的industries字符串
|
||
|
|
industries_str = json.dumps(industries, ensure_ascii=False, indent=2)
|
||
|
|
|
||
|
|
# 替换industries数组
|
||
|
|
pattern = r'const industries = \[[\s\S]*?\n\];'
|
||
|
|
replacement = f'const industries = {industries_str};'
|
||
|
|
|
||
|
|
new_content = re.sub(pattern, replacement, content, count=1)
|
||
|
|
|
||
|
|
# 写入文件
|
||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(new_content)
|
||
|
|
|
||
|
|
# 输出统计信息
|
||
|
|
print(f"✅ 成功替换industries数据")
|
||
|
|
print(f"📊 共 {len(industries)} 个岗位群")
|
||
|
|
for i, industry in enumerate(industries, 1):
|
||
|
|
print(f" {i}. {industry['name']} ({len(industry['positions'])}个岗位)")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
replace_industries_in_mock()
|