#!/usr/bin/env python3 import json import os from datetime import datetime # 读取视觉设计岗位简历.json文件 json_file = '网页未导入数据/视觉设计产业/视觉设计岗位简历.json' mock_file = 'src/mocks/resumeInterviewMock.js' print("正在读取完整的面试题数据...") with open(json_file, 'r', encoding='utf-8') as f: positions_data = json.load(f) # 创建岗位名称到面试题的映射 interview_questions_map = {} for position in positions_data: position_name = position.get("岗位名称", "") interview_content = position.get("面试题内容", "") if position_name and interview_content: # 解析markdown格式的面试题 questions = [] lines = interview_content.split('\n') current_section = "" current_question = None for line in lines: line = line.strip() if line.startswith('# '): # 新的大分类 current_section = line[2:].strip() elif line and line[0].isdigit() and '. 问题' in line: # 保存上一个问题 if current_question: questions.append(current_question) # 提取问题文本 parts = line.split('问题:', 1) if len(parts) > 1: question_text = parts[1].strip() else: parts = line.split('问题:', 1) if len(parts) > 1: question_text = parts[1].strip() else: question_text = line current_question = { "question": question_text, "answer": "", "section": current_section } elif line.startswith('答案:') or line.startswith('答案:'): if current_question: answer = line.replace('答案:', '').replace('答案:', '').strip() current_question["answer"] = answer elif current_question and line and not line.startswith('#') and not (line[0].isdigit() and '. 问题' in line): # 继续添加到答案中(多行答案) if current_question["answer"] and not line.startswith('---'): current_question["answer"] += " " + line # 添加最后一个问题 if current_question: questions.append(current_question) interview_questions_map[position_name] = questions if questions: print(f"解析 {position_name} 的面试题,共 {len(questions)} 个问题") print(f"\n总共找到 {len(interview_questions_map)} 个岗位的面试题") # 读取resumeInterviewMock.js文件 print("\n正在读取 resumeInterviewMock.js...") with open(mock_file, 'r', encoding='utf-8') as f: content = f.read() # 创建备份 backup_file = f"{mock_file}.backup_simple_{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}") # 为每个产业创建面试题数据 def create_industry_questions(position_name, questions): """为特定岗位创建面试题数组""" # 按section分组 sections = {} for q in questions: section = q.get('section', '通用问题') if section not in sections: sections[section] = [] sections[section].append(q) # 创建questions数组 result = [] for section_name, section_questions in sections.items(): if section_questions: # 创建分组 group = { "id": f"group_q{len(result)+1}", "question": f"# {section_name}" if section_name else "# 面试题", "subQuestions": [] } for idx, q in enumerate(section_questions): sub_q = { "id": f"q{len(result)+1}_{idx+1}", "question": q["question"], "answer": q["answer"] if q["answer"] else "请根据实际情况回答。" } group["subQuestions"].append(sub_q) if group["subQuestions"]: # 只添加有内容的分组 result.append(group) return result # 定义产业和岗位的映射关系 industry_positions_map = { "UI设计": ["UI设计师"], "包装设计": ["包装设计师"], "插画设计": ["插画师"], "灯光": ["影视灯光"], "动画设计": ["动画师", "角色原画师", "分镜设计师"], "后期特效": ["特效设计师", "3D特效师", "特效合成师", "CG总监助理"], "剪辑": ["剪辑师", "影视剪辑", "短视频剪辑师"], "品牌设计": ["品牌视觉内容策划", "LOGO设计师", "品牌视觉传播策划管培生"], "平面设计": ["平面设计师", "AIGC设计师", "AI绘画师"], "三维设计": ["3D建模师", "渲染合成师", "材质灯光师", "游戏场景地编", "游戏场景生态设计师助理", "潮玩设计师"], "摄影/摄像": ["摄影师", "影视摄像", "摄影美术指导助理"], "室内设计": ["室内设计师", "美术总监助理"], "调色": ["调色师"], "新媒体运营": ["新媒体运营专员", "自媒体运营专员"], "音频处理": ["音效设计师", "音频编辑师", "混音师", "录音师"], "影视节目策划": ["导演", "文案策划"], "直播": ["社群运营", "直播助理", "直播运营", "直播专员"] } # 手动为每个产业更新questions print("\n开始更新面试题数据...") update_count = 0 # 读取文件行 lines = content.split('\n') new_lines = [] i = 0 while i < len(lines): line = lines[i] new_lines.append(line) # 检查是否是产业名称行 for industry_name, position_names in industry_positions_map.items(): if f'"name": "{industry_name}"' in line: # 找到产业,查找其questions字段 j = i + 1 while j < len(lines) and '"questions":' not in lines[j]: new_lines.append(lines[j]) j += 1 if j < len(lines) and '"questions":' in lines[j]: # 找到questions行 new_lines.append(lines[j]) # 添加 "questions": [ # 跳过旧的questions内容直到找到对应的结束 ] bracket_count = 1 j += 1 while j < len(lines) and bracket_count > 0: if '[' in lines[j]: bracket_count += lines[j].count('[') - lines[j].count(']') elif ']' in lines[j]: bracket_count -= lines[j].count(']') j += 1 # 现在j指向 ] 的下一行 # 插入新的面试题数据 for position_name in position_names: if position_name in interview_questions_map: questions = interview_questions_map[position_name] if questions: questions_data = create_industry_questions(position_name, questions) # 生成JSON字符串(带缩进) questions_str = json.dumps(questions_data, ensure_ascii=False, indent=6)[1:-1] # 去掉外层的[] # 添加正确缩进 indented_questions = '\n'.join([' ' + line for line in questions_str.split('\n')]) new_lines.append(indented_questions) new_lines.append(' ]') update_count += 1 print(f"✓ 已更新 {industry_name} 产业的面试题({len(questions)} 个问题)") # 更新i到j的位置,跳过旧的questions内容 i = j - 1 break else: # 如果没有找到对应的面试题,保持原样 continue break i += 1 # 如果没有更新任何产业,使用原内容 if update_count == 0: print("未能更新任何产业,保持原文件不变") else: # 写回文件 print(f"\n正在写入更新后的内容...") new_content = '\n'.join(new_lines) with open(mock_file, 'w', encoding='utf-8') as f: f.write(new_content) print(f"\n更新完成!") print(f"成功更新: {update_count} 个产业的面试题") # 验证语法 print("\n验证文件语法...") result = os.popen(f'node -c {mock_file} 2>&1').read() if result: print(f"❌ 语法错误: {result}") # 恢复备份 print("正在恢复备份...") 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面试题更新成功!现在每个产业都有完整的面试题数据。")