主要内容: - 包含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>
91 lines
3.5 KiB
Python
91 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
面试题数据换行符修正脚本
|
||
将\\n转换为正确的JSON换行符格式,保留换行效果
|
||
"""
|
||
|
||
import re
|
||
import shutil
|
||
from datetime import datetime
|
||
|
||
def fix_newlines_for_display():
|
||
"""
|
||
修正JS文件中的换行符,使其能正确显示换行效果
|
||
"""
|
||
file_path = "src/mocks/resumeInterviewMock.js"
|
||
|
||
# 创建备份
|
||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||
backup_path = f"{file_path}.backup_display_newlines_{timestamp}"
|
||
shutil.copy2(file_path, backup_path)
|
||
print(f"📦 已创建备份: {backup_path}")
|
||
|
||
try:
|
||
# 读取文件
|
||
with open(file_path, 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
# 统计原始\\n数量
|
||
original_count = content.count('\\\\n')
|
||
print(f"📊 发现 {original_count} 个转义换行符(\\\\n)")
|
||
|
||
# 处理answer字段中的\\n,将其转换为正确的JSON换行符格式
|
||
def fix_newlines_in_answers(match):
|
||
full_match = match.group(0)
|
||
answer_content = match.group(1)
|
||
|
||
# 将\\n转换为正确的JSON换行符\n
|
||
# 注意:\\\\n 在Python字符串中表示 \\n,我们要将其转换为 \n
|
||
fixed_content = answer_content.replace('\\\\n', '\\n')
|
||
|
||
# 清理多余的连续换行符(保留双换行用于段落分隔)
|
||
fixed_content = re.sub(r'\\n{3,}', '\\n\\n', fixed_content)
|
||
|
||
# 清理首尾空白和换行
|
||
fixed_content = fixed_content.strip()
|
||
|
||
return f'"answer": "{fixed_content}"'
|
||
|
||
# 使用正则表达式找到所有answer字段并处理
|
||
answer_pattern = r'"answer":\s*"([^"]*(?:\\.[^"]*)*)"'
|
||
processed_content = re.sub(answer_pattern, fix_newlines_in_answers, content, flags=re.DOTALL)
|
||
|
||
# 统计处理结果
|
||
final_double_backslash_n = processed_content.count('\\\\n')
|
||
final_single_backslash_n = processed_content.count('\\n') - processed_content.count('\\\\n') * 2 # 减去\\n中包含的\n
|
||
|
||
# 写入文件
|
||
with open(file_path, 'w', encoding='utf-8') as f:
|
||
f.write(processed_content)
|
||
|
||
print(f"📊 处理统计:")
|
||
print(f" - 原始\\\\n数量: {original_count}")
|
||
print(f" - 处理后\\\\n数量: {final_double_backslash_n}")
|
||
print(f" - 正确的\\n数量: {final_single_backslash_n}")
|
||
print(f"✅ 已更新 {file_path}")
|
||
|
||
# 验证文件语法
|
||
import subprocess
|
||
try:
|
||
result = subprocess.run(['node', '-c', file_path], capture_output=True, text=True)
|
||
if result.returncode == 0:
|
||
print("✅ JavaScript语法验证通过")
|
||
else:
|
||
print(f"❌ JavaScript语法验证失败: {result.stderr}")
|
||
# 恢复备份
|
||
shutil.copy2(backup_path, file_path)
|
||
print("🔄 已恢复原始文件")
|
||
except Exception as e:
|
||
print(f"⚠️ 无法验证JavaScript语法: {e}")
|
||
|
||
except Exception as e:
|
||
print(f"❌ 处理失败: {e}")
|
||
# 恢复备份
|
||
shutil.copy2(backup_path, file_path)
|
||
print("🔄 已恢复原始文件")
|
||
|
||
if __name__ == "__main__":
|
||
print("🚀 开始修正面试题换行符显示...")
|
||
fix_newlines_for_display()
|
||
print("🎉 处理完成!现在换行符应该能正确显示换行效果了!") |