Create cleanup.py
Browse files- cleanup.py +15 -0
cleanup.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, time
|
| 2 |
+
|
| 3 |
+
OUTPUT_DIR = "outputs"
|
| 4 |
+
|
| 5 |
+
def cleanup(hours=2):
|
| 6 |
+
if not os.path.exists(OUTPUT_DIR):
|
| 7 |
+
return
|
| 8 |
+
|
| 9 |
+
now = time.time()
|
| 10 |
+
|
| 11 |
+
for f in os.listdir(OUTPUT_DIR):
|
| 12 |
+
path = os.path.join(OUTPUT_DIR, f)
|
| 13 |
+
|
| 14 |
+
if os.stat(path).st_mtime < now - hours * 3600:
|
| 15 |
+
os.remove(path)
|