-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleanup.py
24 lines (22 loc) · 973 Bytes
/
cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
# Purges no-longer-needed files from mrms plotting
# Created on 1 May 2022 by Sam Gardner <[email protected]>
from datetime import datetime as dt, timedelta
from os import path, walk, remove
if __name__ == "__main__":
basePath = path.dirname(path.abspath(__file__))
now = dt.now()
outputPath = path.join(basePath, "output")
if path.exists(outputPath):
for root, dirs, files in walk(outputPath):
for name in files:
filepath = path.join(basePath, root, name)
if filepath.endswith(".json"):
deleteAfter = timedelta(days=2)
else:
deleteAfter = timedelta(minutes=20)
createTime = dt.fromtimestamp(path.getmtime(filepath))
if createTime < now - deleteAfter:
remove(filepath)
remove(path.join(basePath, "cached_lats.csv"))
remove(path.join(basePath, "cached_lons.csv"))