import json import re import subprocess def get_existing_ids(file_path): with open(file_path, "r", encoding="utf-8") as f: content = f.read() ids = re.findall(r"- \*\*ID:\*\* `([^`]+)`", content) return set(ids) def get_notebook_sources(): cmd = ["/opt/ai-os/products/ceo/integrations/notebooklm-mcp-cli/.venv/bin/nlm", "source", "list", "a0f8646b-90b1-4a65-bddc-07280aa06a99", "--json"] res = subprocess.run(cmd, capture_output=True, text=True) if res.returncode != 0: print("Error listing sources:", res.stderr) return [] try: return json.loads(res.stdout) except Exception as e: print("JSON parse error:", e) return [] existing = get_existing_ids("./content/research/domains/tourism/master_tourism_vn.md") notebook_sources = get_notebook_sources() notebook_ids = {s["id"] for s in notebook_sources} new_ids = notebook_ids - existing print(f"Existing IDs in file: {len(existing)}") print(f"IDs in NotebookLM: {len(notebook_ids)}") print(f"New IDs to sync: {len(new_ids)}") for s in notebook_sources: if s["id"] in new_ids: print(f"New source: ID={s['id']}, Title={s.get('title', 'N/A')}")