import subprocess import json import time notebook_id = "825ad1eb-2ca9-4576-8dd3-aadf468e5578" nlm_bin = "/opt/ai-os/products/ceo/integrations/notebooklm-mcp-cli/.venv/bin/nlm" res = subprocess.run([nlm_bin, "source", "list", notebook_id, "--json"], capture_output=True, text=True) sources = json.loads(res.stdout) to_delete = [] for s in sources: t = s.get("title", "") sid = s.get("id", "") # 1. tmpxxxx.pdf files if t.startswith("tmp") and t.endswith(".pdf"): to_delete.append((sid, t)) # 2. Krugman international economics duplicate files elif "Krugman, Obstfeld, and Melitz, 2015, International Economics_ Theory and Policy.pdf" in t: to_delete.append((sid, t)) print(f"Total sources identified for deletion: {len(to_delete)}") # Delete in batches of 10 batch_size = 10 deleted_count = 0 for i in range(0, len(to_delete), batch_size): batch = to_delete[i:i + batch_size] ids = [item[0] for item in batch] print(f"Deleting batch {i//batch_size + 1}: {len(ids)} items...") cmd = [nlm_bin, "source", "delete"] + ids + ["--confirm"] del_res = subprocess.run(cmd, capture_output=True, text=True) if del_res.returncode == 0: deleted_count += len(ids) print(f" ✓ Deleted successfully: {del_res.stdout.strip()}") else: print(f" ✗ Batch delete failed: {del_res.stderr.strip()}") time.sleep(0.5) print(f"\nCompleted! Deleted {deleted_count} sources.") # Verify remaining count res_after = subprocess.run([nlm_bin, "source", "list", notebook_id, "--json"], capture_output=True, text=True) sources_after = json.loads(res_after.stdout) print(f"Initial sources: {len(sources)} -> Remaining sources: {len(sources_after)}")