import json import os with open("source_summaries.json", "r", encoding="utf-8") as f: data = json.load(f) md_content = """# Danh mục Tài liệu & Tóm tắt - Báo cáo Du lịch Bản đồ tri thức và tóm tắt chi tiết các nguồn tài liệu (sources) thuộc cụm **Du lịch & Luxury Hospitality** (Báo cáo Du Lịch). ## Tổng quan các nguồn tài liệu Tổng số nguồn tài liệu: {total} --- """.format(total=len(data)) # Group by category prefix if any # e.g., GOV_, NEW_, PP_, RP_, or others categories = { "Chính sách & Quy hoạch Nhà nước (GOV_)": [], "Tin tức & Xu hướng Mới (NEW_)": [], "Nghiên cứu & Học thuật (PP_)": [], "Báo cáo & Thống kê Thị trường (RP_)": [], "Tài liệu khác": [] } for item in data: title = item["title"] if title.startswith("GOV_"): categories["Chính sách & Quy hoạch Nhà nước (GOV_)"].append(item) elif title.startswith("NEW_"): categories["Tin tức & Xu hướng Mới (NEW_)"].append(item) elif title.startswith("PP_"): categories["Nghiên cứu & Học thuật (PP_)"].append(item) elif title.startswith("RP_"): categories["Báo cáo & Thống kê Thị trường (RP_)"].append(item) else: categories["Tài liệu khác"].append(item) for cat_name, items in categories.items(): if not items: continue md_content += f"## {cat_name}\n\n" for i, item in enumerate(items, 1): title = item["title"] summary = item["summary"] keywords = ", ".join([f"`{kw}`" for kw in item["keywords"]]) if item["keywords"] else "Không có" md_content += f"### {i}. {title}\n" md_content += f"- **ID:** `{item['id']}`\n" md_content += f"- **Từ khóa:** {keywords}\n" md_content += f"- **Tóm tắt:** {summary}\n\n" md_content += "---\n\n" # Ensure the output directory exists os.makedirs("/opt/ai-os/products/ceo/company_kb/knowledge", exist_ok=True) dest_path = "/opt/ai-os/products/ceo/company_kb/knowledge/master_tourism.md" with open(dest_path, "w", encoding="utf-8") as f: f.write(md_content.strip() + "\n") print(f"Created file: {dest_path}")