118 lines
4.2 KiB
Python
118 lines
4.2 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
import os
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
# 读取所有产业的完整面试题数据
|
||
|
|
print("正在读取完整面试题数据...")
|
||
|
|
with open('all_industries_with_answers.json', 'r', encoding='utf-8') as f:
|
||
|
|
all_updates = json.load(f)
|
||
|
|
|
||
|
|
# 读取UI设计的完整数据
|
||
|
|
with open('ui_questions_with_answers.json', 'r', encoding='utf-8') as f:
|
||
|
|
ui_questions = json.load(f)
|
||
|
|
|
||
|
|
# 读取当前的resumeInterviewMock.js
|
||
|
|
mock_file = 'src/mocks/resumeInterviewMock.js'
|
||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
# 创建备份
|
||
|
|
backup_file = f"{mock_file}.backup_apply_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
||
|
|
with open(backup_file, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(content)
|
||
|
|
print(f"已创建备份:{backup_file}")
|
||
|
|
|
||
|
|
# 首先更新UI设计的面试题
|
||
|
|
print("\n更新UI设计产业的面试题...")
|
||
|
|
|
||
|
|
# 查找UI设计产业的questions位置
|
||
|
|
ui_pattern = r'("name":\s*"UI设计"[^}]*?"questions":\s*)\[[^\]]*?\]'
|
||
|
|
match = re.search(ui_pattern, content, re.DOTALL)
|
||
|
|
|
||
|
|
if match:
|
||
|
|
# 替换为新的完整数据
|
||
|
|
ui_json_str = json.dumps(ui_questions, ensure_ascii=False, indent=4)
|
||
|
|
new_content = content[:match.start(1)] + match.group(1) + ui_json_str + content[match.end():]
|
||
|
|
|
||
|
|
# 写入文件
|
||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(new_content)
|
||
|
|
|
||
|
|
print("✓ UI设计产业面试题已更新为完整版本")
|
||
|
|
|
||
|
|
# 验证语法
|
||
|
|
result = os.popen(f'node -c {mock_file} 2>&1').read()
|
||
|
|
if result:
|
||
|
|
print(f"❌ 语法错误:{result}")
|
||
|
|
# 恢复备份
|
||
|
|
with open(backup_file, 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(content)
|
||
|
|
print("已恢复备份")
|
||
|
|
else:
|
||
|
|
print("✓ 语法验证通过")
|
||
|
|
|
||
|
|
# 继续更新其他产业
|
||
|
|
print("\n继续更新其他产业...")
|
||
|
|
content = new_content # 使用更新后的内容
|
||
|
|
|
||
|
|
industry_map = {
|
||
|
|
"包装设计": "包装设计",
|
||
|
|
"插画设计": "插画设计",
|
||
|
|
"灯光": "灯光",
|
||
|
|
"动画设计": "动画设计",
|
||
|
|
"后期特效": "后期特效",
|
||
|
|
"剪辑": "剪辑",
|
||
|
|
"品牌设计": "品牌设计",
|
||
|
|
"平面设计": "平面设计",
|
||
|
|
"三维设计": "三维设计",
|
||
|
|
"摄影/摄像": "摄影/摄像",
|
||
|
|
"室内设计": "室内设计",
|
||
|
|
"调色": "调色",
|
||
|
|
"新媒体运营": "新媒体运营",
|
||
|
|
"音频处理": "音频处理",
|
||
|
|
"影视节目策划": "影视节目策划",
|
||
|
|
"直播": "直播"
|
||
|
|
}
|
||
|
|
|
||
|
|
update_count = 1 # UI设计已更新
|
||
|
|
|
||
|
|
for update_data in all_updates:
|
||
|
|
industry_name = update_data['industry']
|
||
|
|
if industry_name in industry_map:
|
||
|
|
mock_industry = industry_map[industry_name]
|
||
|
|
|
||
|
|
# 查找并替换
|
||
|
|
pattern = rf'("name":\s*"{re.escape(mock_industry)}"[^}}]*?"questions":\s*)\[[^\]]*?\]'
|
||
|
|
match = re.search(pattern, content, re.DOTALL)
|
||
|
|
|
||
|
|
if match:
|
||
|
|
# 生成JSON
|
||
|
|
questions_json = json.dumps(update_data['questions'], ensure_ascii=False, indent=4)
|
||
|
|
content = content[:match.start(1)] + match.group(1) + questions_json + content[match.end():]
|
||
|
|
update_count += 1
|
||
|
|
print(f"✓ {industry_name} 已更新")
|
||
|
|
|
||
|
|
# 最终写入
|
||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(content)
|
||
|
|
|
||
|
|
# 最终验证
|
||
|
|
print(f"\n验证最终文件语法...")
|
||
|
|
result = os.popen(f'node -c {mock_file} 2>&1').read()
|
||
|
|
if result:
|
||
|
|
print(f"❌ 最终语法错误:{result}")
|
||
|
|
# 恢复备份
|
||
|
|
with open(backup_file, 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(content)
|
||
|
|
print("已恢复备份")
|
||
|
|
else:
|
||
|
|
print("✓ 所有语法验证通过")
|
||
|
|
print(f"\n成功更新 {update_count} 个产业的面试题为完整版本!")
|
||
|
|
else:
|
||
|
|
print("✗ 未找到UI设计产业")
|