-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathclear_mwdb_simple.py
More file actions
37 lines (29 loc) · 908 Bytes
/
clear_mwdb_simple.py
File metadata and controls
37 lines (29 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
"""
Simple script to delete all files from MWDB using mwdblib.
"""
from mwdblib import MWDB
# Use the admin API key
api_key = os.environ.get("MWDB_API_KEY")
if not api_key:
# Look for it in the .env file possibly or error out
print("Error: MWDB_API_KEY environment variable not set.")
exit(1)
mwdb = MWDB(api_url="http://mwdb-core:8080/api/", api_key=api_key)
print("Fetching all files...")
files = list(mwdb.search_files("")) # Empty query gets all files
print(f"Found {len(files)} files to delete.")
if len(files) == 0:
print("No files to delete.")
exit(0)
deleted = 0
failed = 0
for i, f in enumerate(files, 1):
try:
print(f"[{i}/{len(files)}] Deleting {f.sha256}...")
f.remove()
deleted += 1
except Exception as e:
print(f" ERROR: {e}")
failed += 1
print(f"\nDeleted {deleted} files, {failed} failed.")