90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
最终验证所有图片路径是否正确
|
||
|
|
"""
|
||
|
|
|
||
|
|
import re
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
def validate_order_class(order_dir: Path):
|
||
|
|
"""验证单个订单班"""
|
||
|
|
notion_dir = order_dir / "notion文稿"
|
||
|
|
if not notion_dir.exists():
|
||
|
|
return None
|
||
|
|
|
||
|
|
image_dir = notion_dir / "image"
|
||
|
|
if not image_dir.exists():
|
||
|
|
return {"error": "没有image目录"}
|
||
|
|
|
||
|
|
# 获取所有实际存在的图片
|
||
|
|
actual_images = {img.name for img in image_dir.glob("*.jpg")}
|
||
|
|
|
||
|
|
# 获取所有MD文件中的引用
|
||
|
|
referenced_images = set()
|
||
|
|
for md_file in notion_dir.glob("*.md"):
|
||
|
|
if md_file.name == "图片索引.md":
|
||
|
|
continue
|
||
|
|
|
||
|
|
content = md_file.read_text(encoding='utf-8')
|
||
|
|
# 查找所有图片引用
|
||
|
|
matches = re.findall(r'!\[.*?\]\(./image/([^)]+\.jpg)\)', content)
|
||
|
|
referenced_images.update(matches)
|
||
|
|
|
||
|
|
# 找出问题
|
||
|
|
missing = referenced_images - actual_images
|
||
|
|
unused = actual_images - referenced_images - {"图片名.jpg"} # 排除示例文件
|
||
|
|
|
||
|
|
return {
|
||
|
|
"total_images": len(actual_images),
|
||
|
|
"referenced": len(referenced_images),
|
||
|
|
"missing": list(missing),
|
||
|
|
"unused": list(unused)
|
||
|
|
}
|
||
|
|
|
||
|
|
def main():
|
||
|
|
base_path = Path("/Users/xiaoqi/Documents/Dev/Project/2025-09-08_n8nDEMO演示/data/订单班文档资料")
|
||
|
|
|
||
|
|
order_classes = [
|
||
|
|
"文旅", "财经商贸", "食品", "智能开发", "智能制造",
|
||
|
|
"视觉设计", "交通物流", "土木", "大健康", "能源",
|
||
|
|
"化工", "环保"
|
||
|
|
]
|
||
|
|
|
||
|
|
print("=" * 60)
|
||
|
|
print("最终验证报告")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
all_good = True
|
||
|
|
|
||
|
|
for order_class in order_classes:
|
||
|
|
order_dir = base_path / order_class
|
||
|
|
result = validate_order_class(order_dir)
|
||
|
|
|
||
|
|
if result is None:
|
||
|
|
continue
|
||
|
|
|
||
|
|
print(f"\n【{order_class}】")
|
||
|
|
|
||
|
|
if "error" in result:
|
||
|
|
print(f" ❌ {result['error']}")
|
||
|
|
all_good = False
|
||
|
|
elif result["missing"]:
|
||
|
|
print(f" ⚠️ 找不到 {len(result['missing'])} 个引用的图片:")
|
||
|
|
for img in result["missing"][:3]:
|
||
|
|
print(f" - {img}")
|
||
|
|
all_good = False
|
||
|
|
else:
|
||
|
|
print(f" ✅ 所有 {result['referenced']} 个引用都正确")
|
||
|
|
print(f" 实际图片: {result['total_images']} 张")
|
||
|
|
if result["unused"]:
|
||
|
|
print(f" 未使用: {len(result['unused'])} 张")
|
||
|
|
|
||
|
|
print("\n" + "=" * 60)
|
||
|
|
if all_good:
|
||
|
|
print("✅ 所有图片路径验证通过!")
|
||
|
|
else:
|
||
|
|
print("⚠️ 有一些路径需要检查")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|