#!/usr/bin/env python3 """ Cleanup script to delete all wiki pages via REST API. This will trigger automatic vector and graph cleanup for each page. """ import requests import time import sys # Configuration BASE_URL = "http://192.168.86.149:8089" API_KEY = "af88ed8f44bed81bdb20d0534f1c4547340b29e2aba4963f61a71b993d7eb6e5" USER = "jpmschweitzer" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } def list_all_pages(): """List all wiki pages.""" url = f"{BASE_URL}/wiki/pages" params = {"user": USER, "limit": 200} print(f"๐Ÿ” Listing all pages for user: {USER}") response = requests.get(url, headers=headers, params=params) if response.status_code != 200: print(f"โŒ Failed to list pages: {response.status_code}") print(response.text) return [] data = response.json() pages = data.get("pages", []) print(f"๐Ÿ“š Found {len(pages)} pages") return pages def delete_page(page_id, title): """Delete a single wiki page.""" url = f"{BASE_URL}/wiki/pages/{page_id}" params = {"user": USER} print(f"๐Ÿ—‘๏ธ Deleting page {page_id}: {title}") response = requests.delete(url, headers=headers, params=params) if response.status_code == 200: print(f" โœ… Deleted successfully") return True else: print(f" โŒ Failed: {response.status_code}") print(f" {response.text}") return False def main(): print("=" * 60) print("๐Ÿงน Wiki Cleanup Script") print("=" * 60) print() # List all pages pages = list_all_pages() if not pages: print("โœจ No pages found. Wiki is already clean!") return print() print(f"โš ๏ธ WARNING: About to delete {len(pages)} pages!") print(" This will also delete:") print(" - Vector embeddings in Qdrant") print(" - Document nodes in Neo4j") print() # Ask for confirmation response = input("Continue? (yes/no): ").strip().lower() if response != "yes": print("โŒ Cancelled") return print() print("๐Ÿš€ Starting deletion...") print() # Delete each page success_count = 0 failed_count = 0 for i, page in enumerate(pages, 1): page_id = page.get("id") title = page.get("title", "Untitled") print(f"[{i}/{len(pages)}] ", end="") if delete_page(page_id, title): success_count += 1 else: failed_count += 1 # Small delay to avoid overwhelming the API time.sleep(0.2) print() print("=" * 60) print("๐Ÿ“Š Cleanup Summary") print("=" * 60) print(f"โœ… Successfully deleted: {success_count} pages") print(f"โŒ Failed to delete: {failed_count} pages") print(f"๐Ÿ“ Total pages: {len(pages)}") print() if success_count > 0: print("๐Ÿงน Background cleanup tasks are running to remove:") print(" - Vector embeddings from Qdrant") print(" - Document nodes from Neo4j") print() print("โœจ Wiki cleanup complete!") if __name__ == "__main__": try: main() except KeyboardInterrupt: print("\n\nโŒ Interrupted by user") sys.exit(1) except Exception as e: print(f"\n\nโŒ Error: {e}") sys.exit(1)