107 lines
3.4 KiB
Python
107 lines
3.4 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
import datetime
|
|||
|
|
import shutil
|
|||
|
|
|
|||
|
|
def limit_automation_control_questions():
|
|||
|
|
"""
|
|||
|
|
限制自动化控制岗位群的面试题为前10个
|
|||
|
|
"""
|
|||
|
|
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}")
|
|||
|
|
|
|||
|
|
# 读取文件内容
|
|||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
|||
|
|
lines = f.readlines()
|
|||
|
|
|
|||
|
|
# 查找自动化控制部分
|
|||
|
|
in_automation = False
|
|||
|
|
in_subquestions = False
|
|||
|
|
question_count = 0
|
|||
|
|
bracket_level = 0
|
|||
|
|
start_line = -1
|
|||
|
|
new_lines = []
|
|||
|
|
|
|||
|
|
for i, line in enumerate(lines):
|
|||
|
|
# 检查是否进入自动化控制部分
|
|||
|
|
if '"name": "自动化控制"' in line:
|
|||
|
|
in_automation = True
|
|||
|
|
|
|||
|
|
# 如果在自动化控制部分,查找subQuestions
|
|||
|
|
if in_automation and '"subQuestions":' in line:
|
|||
|
|
in_subquestions = True
|
|||
|
|
start_line = i
|
|||
|
|
bracket_level = 0
|
|||
|
|
question_count = 0
|
|||
|
|
new_lines.append(line)
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 如果在subQuestions数组中
|
|||
|
|
if in_subquestions:
|
|||
|
|
# 计算括号层级
|
|||
|
|
bracket_level += line.count('[') - line.count(']')
|
|||
|
|
bracket_level += line.count('{') - line.count('}')
|
|||
|
|
|
|||
|
|
# 计算问题数量(通过id字段)
|
|||
|
|
if '"id": "q' in line:
|
|||
|
|
question_count += 1
|
|||
|
|
|
|||
|
|
# 如果已经有10个问题,跳过后续内容直到数组结束
|
|||
|
|
if question_count > 10:
|
|||
|
|
if bracket_level == 0 and ']' in line:
|
|||
|
|
# 到达数组结束,添加结束符
|
|||
|
|
new_lines.append(' ]\n')
|
|||
|
|
in_subquestions = False
|
|||
|
|
in_automation = False
|
|||
|
|
question_count = 0
|
|||
|
|
# 跳过超过10个的问题内容
|
|||
|
|
continue
|
|||
|
|
else:
|
|||
|
|
# 保留前10个问题
|
|||
|
|
new_lines.append(line)
|
|||
|
|
|
|||
|
|
# 检查数组是否结束
|
|||
|
|
if bracket_level == 0 and ']' in line and question_count > 0:
|
|||
|
|
in_subquestions = False
|
|||
|
|
in_automation = False
|
|||
|
|
question_count = 0
|
|||
|
|
else:
|
|||
|
|
new_lines.append(line)
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.writelines(new_lines)
|
|||
|
|
|
|||
|
|
print("✅ 成功限制自动化控制岗位群的面试题为前10个")
|
|||
|
|
|
|||
|
|
# 验证结果
|
|||
|
|
verify_result(mock_file)
|
|||
|
|
|
|||
|
|
def verify_result(mock_file):
|
|||
|
|
"""
|
|||
|
|
验证自动化控制的问题数量
|
|||
|
|
"""
|
|||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 查找自动化控制部分的问题数量
|
|||
|
|
pattern = r'"name": "自动化控制"[\s\S]*?"subQuestions":[\s\S]*?\]'
|
|||
|
|
match = re.search(pattern, content)
|
|||
|
|
|
|||
|
|
if match:
|
|||
|
|
section = match.group(0)
|
|||
|
|
question_count = len(re.findall(r'"id": "q\d+"', section))
|
|||
|
|
print(f"✅ 验证:自动化控制岗位群现有 {question_count} 个问题")
|
|||
|
|
|
|||
|
|
# 统计所有问题总数
|
|||
|
|
total_questions = len(re.findall(r'"id": "q\d+"', content))
|
|||
|
|
print(f"📊 所有岗位群总计:{total_questions} 个面试题")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
limit_automation_control_questions()
|