98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
替换面试状态数据
|
|||
|
|
将能源岗位面试状态数据转换为现有格式并替换到interviewStatus.json
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
def transform_energy_interview_data(energy_data):
|
|||
|
|
"""将能源面试状态数据转换为现有格式"""
|
|||
|
|
transformed = []
|
|||
|
|
|
|||
|
|
for item in energy_data:
|
|||
|
|
# 构建阶段日期字符串
|
|||
|
|
stage_prefix = ""
|
|||
|
|
if "面试结果" in item["岗位内推流程"]:
|
|||
|
|
stage_prefix = "面试结果"
|
|||
|
|
elif "Offer" in item["岗位内推流程"]:
|
|||
|
|
stage_prefix = "收到Offer"
|
|||
|
|
elif "HR评估" in item["岗位内推流程"]:
|
|||
|
|
stage_prefix = "HR评估"
|
|||
|
|
elif "面试" in item["岗位内推流程"]:
|
|||
|
|
stage_prefix = "面试日期"
|
|||
|
|
else:
|
|||
|
|
stage_prefix = item["岗位内推流程"]
|
|||
|
|
|
|||
|
|
# 格式化时间 (去掉时分秒部分)
|
|||
|
|
time_str = item["流程时间"].split(" ")[0] if " " in item["流程时间"] else item["流程时间"]
|
|||
|
|
|
|||
|
|
# 构建阶段日期
|
|||
|
|
stage_date = f"{stage_prefix}:{time_str}"
|
|||
|
|
|
|||
|
|
# 构建面试状态
|
|||
|
|
interview_status = item["内容"]
|
|||
|
|
|
|||
|
|
transformed_item = {
|
|||
|
|
"查询岗位名称": item["查询岗位名称"],
|
|||
|
|
"阶段日期": stage_date,
|
|||
|
|
"面试状态": interview_status
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
transformed.append(transformed_item)
|
|||
|
|
|
|||
|
|
return transformed
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
# 读取能源岗位面试状态数据
|
|||
|
|
energy_data_path = '网页未导入数据/能源产业/能源岗位面试状态.json'
|
|||
|
|
target_path = 'src/data/interviewStatus.json'
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
backup_path = f'{target_path}.backup_{datetime.now().strftime("%Y%m%d_%H%M%S")}'
|
|||
|
|
|
|||
|
|
print(f"读取能源面试状态数据: {energy_data_path}")
|
|||
|
|
with open(energy_data_path, 'r', encoding='utf-8') as f:
|
|||
|
|
energy_interview_data = json.load(f)
|
|||
|
|
|
|||
|
|
print(f"共读取到 {len(energy_interview_data)} 个面试状态")
|
|||
|
|
|
|||
|
|
# 如果目标文件存在,先备份
|
|||
|
|
try:
|
|||
|
|
print(f"备份原文件到: {backup_path}")
|
|||
|
|
with open(target_path, 'r', encoding='utf-8') as f:
|
|||
|
|
original_data = f.read()
|
|||
|
|
with open(backup_path, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(original_data)
|
|||
|
|
except FileNotFoundError:
|
|||
|
|
print("原文件不存在,创建新文件")
|
|||
|
|
|
|||
|
|
# 转换数据格式
|
|||
|
|
transformed_data = transform_energy_interview_data(energy_interview_data)
|
|||
|
|
|
|||
|
|
# 写入新数据
|
|||
|
|
print(f"写入 {len(transformed_data)} 个面试状态到: {target_path}")
|
|||
|
|
with open(target_path, 'w', encoding='utf-8') as f:
|
|||
|
|
json.dump(transformed_data, f, ensure_ascii=False, indent=2)
|
|||
|
|
|
|||
|
|
print("✅ 数据替换完成!")
|
|||
|
|
print(f"- 原文件已备份: {backup_path}")
|
|||
|
|
print(f"- 新数据已写入: {target_path}")
|
|||
|
|
print(f"- 共替换 {len(transformed_data)} 个面试状态")
|
|||
|
|
|
|||
|
|
# 验证数据
|
|||
|
|
with open(target_path, 'r', encoding='utf-8') as f:
|
|||
|
|
verify_data = json.load(f)
|
|||
|
|
print(f"✅ 验证: 文件包含 {len(verify_data)} 个面试状态")
|
|||
|
|
|
|||
|
|
# 显示前3个面试状态作为验证
|
|||
|
|
print("\n前3个面试状态:")
|
|||
|
|
for i, status in enumerate(verify_data[:3]):
|
|||
|
|
print(f" {i+1}. {status['查询岗位名称']}")
|
|||
|
|
print(f" 阶段: {status['阶段日期']}")
|
|||
|
|
print(f" 状态: {status['面试状态']}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|