Files
ALL-teach_sys/frontend_大健康/update_interview_questions_simple.py
KQL cd2e307402 初始化12个产业教务系统项目
主要内容:
- 包含12个产业的完整教务系统前端代码
- 智能启动脚本 (start-industry.sh)
- 可视化产业导航页面 (index.html)
- 项目文档 (README.md)

优化内容:
- 删除所有node_modules和.yoyo文件夹,从7.5GB减少到2.7GB
- 添加.gitignore文件避免上传不必要的文件
- 自动依赖管理和智能启动系统

产业列表:
1. 文旅产业 (5150)
2. 智能制造 (5151)
3. 智能开发 (5152)
4. 财经商贸 (5153)
5. 视觉设计 (5154)
6. 交通物流 (5155)
7. 大健康 (5156)
8. 土木水利 (5157)
9. 食品产业 (5158)
10. 化工产业 (5159)
11. 能源产业 (5160)
12. 环保产业 (5161)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 14:14:14 +08:00

192 lines
6.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
更新简历与面试题页面的面试题数据
直接替换法避免复杂的JavaScript解析
"""
import json
import re
import sys
from datetime import datetime
def load_health_resume_data():
"""加载大健康岗位简历数据"""
try:
with open('网页未导入数据/大健康产业/大健康岗位简历.json', 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as e:
print(f"Error loading health resume data: {e}")
return None
def parse_interview_content(content):
"""解析面试题内容转换为JavaScript格式"""
if not content:
return '[]'
questions_js = []
# 按大标题分割(# 一、二、三等)
sections = re.split(r'\n# ([一二三四五六七八九十]+、[^#\n]+)', content)
if len(sections) < 2:
return '[]'
question_id = 1
for i in range(1, len(sections), 2):
if i + 1 < len(sections):
section_title = sections[i].strip()
section_content = sections[i + 1].strip()
# 解析每个section中的问题
sub_questions_js = []
# 按问题编号分割 (1. 2. 3. 等)
question_parts = re.split(r'\n\s*(\d+\.)\s+', section_content)
sub_question_id = 1
for j in range(1, len(question_parts), 2):
if j + 1 < len(question_parts):
question_num = question_parts[j].strip()
question_block = question_parts[j + 1].strip()
# 提取问题和答案
lines = question_block.split('\n')
question_text = ""
answer_text = ""
in_answer = False
for line in lines:
line = line.strip()
if line.startswith('示例答案:'):
in_answer = True
continue
if not in_answer and line and not line.startswith('示例答案:'):
if question_text:
question_text += " "
question_text += line
elif in_answer and line:
if answer_text:
answer_text += "\\n"
answer_text += line
if question_text:
# 转义引号
question_text = question_text.replace('"', '\\"')
answer_text = answer_text.replace('"', '\\"')
sub_question_template = ''' {{
"id": "q{}_{}",
"question": "{}",
"answer": "{}"
}}'''.format(question_id, sub_question_id, question_text, answer_text)
sub_questions_js.append(sub_question_template)
sub_question_id += 1
if sub_questions_js:
section_title_escaped = section_title.replace('"', '\\"')
question_template = ''' {{
"id": "group_q{}",
"question": "# {}",
"subQuestions": [
{}
]
}}'''.format(question_id, section_title_escaped, ',\n'.join(sub_questions_js))
questions_js.append(question_template)
question_id += 1
if questions_js:
return '''[
{}
]'''.format(',\n'.join(questions_js))
else:
return '[]'
def update_interview_questions(health_data):
"""更新面试题数据"""
try:
# 读取现有文件
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
content = f.read()
# 创建岗位到面试题的映射
position_to_questions = {}
for item in health_data:
position_name = item.get('岗位名称', '')
interview_content = item.get('面试题内容', '')
if position_name and interview_content:
questions_js = parse_interview_content(interview_content)
position_to_questions[position_name] = questions_js
# 更新每个岗位的面试题
updated_content = content
update_count = 0
for position_name, questions_js in position_to_questions.items():
# 查找该岗位的结构并在requirements后添加questions字段
pattern = rf'"title": "{re.escape(position_name)}",[^}}]+?"requirements": \[[^\]]*?\]'
def add_questions(match):
matched_text = match.group(0)
# 在requirements后添加questions字段
return matched_text + ',\n "questions": ' + questions_js
new_content = re.sub(pattern, add_questions, updated_content, flags=re.DOTALL)
if new_content != updated_content:
updated_content = new_content
update_count += 1
print(f"Added interview questions for position: {position_name}")
else:
# 如果已存在questions字段则替换
pattern2 = rf'"title": "{re.escape(position_name)}",[^}}]+?"questions": \[[^\]]*?\]'
def replace_questions(match):
matched_text = match.group(0)
# 替换questions数组
return re.sub(r'"questions": \[[^\]]*?\]', f'"questions": {questions_js}', matched_text)
new_content2 = re.sub(pattern2, replace_questions, updated_content, flags=re.DOTALL)
if new_content2 != updated_content:
updated_content = new_content2
update_count += 1
print(f"Updated interview questions for position: {position_name}")
# 写回文件
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
f.write(updated_content)
print(f"Interview questions updated successfully! Updated {update_count} positions.")
return True
except Exception as e:
print(f"Error updating interview questions: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""主函数"""
print("Starting to update interview questions...")
# 加载数据
health_data = load_health_resume_data()
if not health_data:
print("Failed to load health resume data")
return False
# 更新面试题数据
success = update_interview_questions(health_data)
if success:
print("Interview questions update completed!")
else:
print("Interview questions update failed!")
return success
if __name__ == "__main__":
main()