import os import shutil import re ROOT = "/opt/ai-os/products/ceo/company_kb" INGEST = os.path.join(ROOT, "notebooklm_ingest") KNOWLEDGE = os.path.join(ROOT, "knowledge") # Create structure os.makedirs(os.path.join(KNOWLEDGE, "tourism"), exist_ok=True) os.makedirs(os.path.join(KNOWLEDGE, "policy"), exist_ok=True) # Find directories tourism_dir = None policy_dir = None for d in os.listdir(INGEST): if "Báo cáo Du Lịch" in d: tourism_dir = os.path.join(INGEST, d) elif "Thạc sĩ Phân tích Chính sách" in d: policy_dir = os.path.join(INGEST, d) def clean_and_copy(src_dir, dest_dir): if not src_dir or not os.path.isdir(src_dir): print(f"Skipping {src_dir}") return count = 0 for fn in os.listdir(src_dir): if not fn.endswith(".md") or fn == "_notebook.json": continue fp = os.path.join(src_dir, fn) with open(fp, "r", encoding="utf-8", errors="replace") as f: content = f.read() # Optional: remove NotebookLM metadata block # metadata is usually between "- **Notebook:**" and "---" # We can just keep it for now but organize them cleanly. # We might want to shorten filename because some are too long new_fn = fn[:100] + ".md" if len(fn) > 100 else fn dest_fp = os.path.join(dest_dir, new_fn) with open(dest_fp, "w", encoding="utf-8") as f: f.write(content) count += 1 print(f"Ingested {count} files to {dest_dir}") clean_and_copy(tourism_dir, os.path.join(KNOWLEDGE, "tourism")) clean_and_copy(policy_dir, os.path.join(KNOWLEDGE, "policy"))