Spaces:
Runtime error
Runtime error
Download cleanup.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/cleanup.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/cleanup.py
-
curl -L -o cleanup.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/cleanup.py
1.34 kB
| import os | |
| import time | |
| from datetime import datetime, timedelta | |
| from core.config import settings | |
| OUTPUT_DIR = settings.OUTPUT_DIR | |
| TEMP_DIR = settings.TEMP_DIR | |
| TTL_HOURS = 6 # delete files older than 6 hours (change if needed) | |
| def auto_cleanup(): | |
| now = datetime.utcnow() | |
| cutoff = now - timedelta(hours=TTL_HOURS) | |
| removed = [] | |
| for folder in [OUTPUT_DIR, TEMP_DIR]: | |
| if not os.path.exists(folder): | |
| continue | |
| for filename in os.listdir(folder): | |
| file_path = os.path.join(folder, filename) | |
| try: | |
| # modification time | |
| mtime = datetime.utcfromtimestamp(os.path.getmtime(file_path)) | |
| if mtime < cutoff: | |
| if os.path.isdir(file_path): | |
| import shutil | |
| shutil.rmtree(file_path, ignore_errors=True) | |
| removed.append(file_path) | |
| else: | |
| os.remove(file_path) | |
| removed.append(file_path) | |
| except Exception: | |
| continue | |
| if removed: | |
| print(f"[CLEANUP] Removed {len(removed)} old files:") | |
| for path in removed: | |
| print(" -", path) | |
| else: | |
| print("[CLEANUP] No old files found.") | |
| if __name__ == "__main__": | |
| auto_cleanup() | |