48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import json
|
||
|
|
|
||
|
|
# 读取视觉设计项目案例数据
|
||
|
|
with open('网页未导入数据/视觉设计产业/视觉设计项目案例.json', 'r', encoding='utf-8') as f:
|
||
|
|
visual_projects = json.load(f)
|
||
|
|
|
||
|
|
# 创建附件数据映射
|
||
|
|
attachments_map = {}
|
||
|
|
for project in visual_projects:
|
||
|
|
name = project.get("案例名称", "")
|
||
|
|
attachments_str = project.get("附件", "")
|
||
|
|
|
||
|
|
if attachments_str:
|
||
|
|
# 分割附件字符串
|
||
|
|
files = [f.strip() for f in attachments_str.split(',')]
|
||
|
|
attachments_list = []
|
||
|
|
|
||
|
|
for file in files:
|
||
|
|
ext = file.split('.')[-1].lower()
|
||
|
|
# 判断文件类型
|
||
|
|
file_type = 'document'
|
||
|
|
if ext in ['jpg', 'jpeg', 'png', 'gif']:
|
||
|
|
file_type = 'image'
|
||
|
|
elif ext in ['mp4', 'avi', 'mov']:
|
||
|
|
file_type = 'video'
|
||
|
|
elif ext == 'pdf':
|
||
|
|
file_type = 'pdf'
|
||
|
|
elif ext == 'psd':
|
||
|
|
file_type = 'design'
|
||
|
|
elif ext in ['doc', 'docx']:
|
||
|
|
file_type = 'word'
|
||
|
|
|
||
|
|
attachments_list.append({
|
||
|
|
'name': file,
|
||
|
|
'type': file_type,
|
||
|
|
'url': f'/attachments/{file}'
|
||
|
|
})
|
||
|
|
|
||
|
|
attachments_map[name] = attachments_list
|
||
|
|
|
||
|
|
# 输出结果
|
||
|
|
print("附件数据映射:")
|
||
|
|
for name, attachments in attachments_map.items():
|
||
|
|
print(f"\n{name}:")
|
||
|
|
print(f" 附件数量: {len(attachments)}")
|
||
|
|
if len(attachments) > 0:
|
||
|
|
print(f" 第一个附件: {attachments[0]['name']}")
|