97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import shutil
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
def update_energy_hr_data():
|
|||
|
|
"""更新侧边栏和HR访问量弹窗的能源产业HR数据"""
|
|||
|
|
|
|||
|
|
# 读取能源产业HR数据
|
|||
|
|
with open('网页未导入数据/企业HR头像.json', 'r', encoding='utf-8') as f:
|
|||
|
|
all_hrs = json.load(f)
|
|||
|
|
|
|||
|
|
# 筛选能源产业的HR
|
|||
|
|
energy_hrs = [hr for hr in all_hrs if hr['所属产业'] == '能源']
|
|||
|
|
print(f"找到 {len(energy_hrs)} 个能源产业HR")
|
|||
|
|
|
|||
|
|
# 备份Sidebar组件
|
|||
|
|
sidebar_file = 'src/components/Sidebar/index.jsx'
|
|||
|
|
sidebar_backup = f"src/components/Sidebar/index.jsx.backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|||
|
|
shutil.copy(sidebar_file, sidebar_backup)
|
|||
|
|
print(f"已备份侧边栏组件到: {sidebar_backup}")
|
|||
|
|
|
|||
|
|
# 备份HRVisitModal组件
|
|||
|
|
modal_file = 'src/components/HRVisitModal/index.jsx'
|
|||
|
|
modal_backup = f"src/components/HRVisitModal/index.jsx.backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|||
|
|
shutil.copy(modal_file, modal_backup)
|
|||
|
|
print(f"已备份HR访问弹窗组件到: {modal_backup}")
|
|||
|
|
|
|||
|
|
# 更新Sidebar组件中的HR数据(显示前3个)
|
|||
|
|
with open(sidebar_file, 'r', encoding='utf-8') as f:
|
|||
|
|
sidebar_content = f.read()
|
|||
|
|
|
|||
|
|
# 找到HR数据部分并替换
|
|||
|
|
sidebar_hr_data = []
|
|||
|
|
for i, hr in enumerate(energy_hrs[:3]):
|
|||
|
|
sidebar_hr_data.append(f'''{{
|
|||
|
|
id: {i + 1},
|
|||
|
|
avatar: "{hr['url']}",
|
|||
|
|
name: "{hr['企业HR名称']}",
|
|||
|
|
company: "{hr['企业HR所属公司']}"
|
|||
|
|
}}''')
|
|||
|
|
|
|||
|
|
sidebar_hrs_str = ','.join(sidebar_hr_data)
|
|||
|
|
|
|||
|
|
# 替换侧边栏中的HR数据
|
|||
|
|
# 找到hrAvatars定义的位置
|
|||
|
|
import re
|
|||
|
|
hr_avatars_pattern = r'const hrAvatars = \[(.*?)\];'
|
|||
|
|
hr_avatars_match = re.search(hr_avatars_pattern, sidebar_content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if hr_avatars_match:
|
|||
|
|
new_hr_avatars = f'const hrAvatars = [{sidebar_hrs_str}];'
|
|||
|
|
sidebar_content = sidebar_content[:hr_avatars_match.start()] + new_hr_avatars + sidebar_content[hr_avatars_match.end():]
|
|||
|
|
|
|||
|
|
with open(sidebar_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(sidebar_content)
|
|||
|
|
print("已更新侧边栏HR数据")
|
|||
|
|
|
|||
|
|
# 更新HRVisitModal组件中的HR数据(显示全部14个)
|
|||
|
|
with open(modal_file, 'r', encoding='utf-8') as f:
|
|||
|
|
modal_content = f.read()
|
|||
|
|
|
|||
|
|
# 构建HR数据数组
|
|||
|
|
modal_hr_data = []
|
|||
|
|
for i, hr in enumerate(energy_hrs):
|
|||
|
|
modal_hr_data.append(f''' {{
|
|||
|
|
id: {i + 1},
|
|||
|
|
avatar: "{hr['url']}",
|
|||
|
|
name: "{hr['企业HR名称']}",
|
|||
|
|
company: "{hr['企业HR所属公司']}",
|
|||
|
|
position: "HR",
|
|||
|
|
visitCount: {25 - i}
|
|||
|
|
}}''')
|
|||
|
|
|
|||
|
|
modal_hrs_str = ',\n'.join(modal_hr_data)
|
|||
|
|
|
|||
|
|
# 替换弹窗中的HR数据
|
|||
|
|
hr_data_pattern = r'const hrData = \[(.*?)\];'
|
|||
|
|
hr_data_match = re.search(hr_data_pattern, modal_content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if hr_data_match:
|
|||
|
|
new_hr_data = f'const hrData = [\n{modal_hrs_str}\n ];'
|
|||
|
|
modal_content = modal_content[:hr_data_match.start()] + new_hr_data + modal_content[hr_data_match.end():]
|
|||
|
|
|
|||
|
|
with open(modal_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(modal_content)
|
|||
|
|
print("已更新HR访问弹窗数据")
|
|||
|
|
|
|||
|
|
# 显示更新结果
|
|||
|
|
print("\n能源产业HR列表:")
|
|||
|
|
for i, hr in enumerate(energy_hrs, 1):
|
|||
|
|
print(f"{i}. {hr['企业HR名称']} - {hr['企业HR所属公司']}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
update_energy_hr_data()
|