initial commit
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
import os, time, shutil
|
||||
|
||||
DATA_ROOT = "/var/www/WEATHER/public_html/data"
|
||||
TTL = 24 * 3600 # 24 hours
|
||||
|
||||
def is_old(path):
|
||||
try:
|
||||
age = time.time() - os.path.getmtime(path)
|
||||
return age > TTL
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def main():
|
||||
# Remove old files
|
||||
for root, dirs, files in os.walk(DATA_ROOT, topdown=False):
|
||||
for name in files:
|
||||
p = os.path.join(root, name)
|
||||
if is_old(p):
|
||||
try:
|
||||
os.remove(p)
|
||||
except Exception as e:
|
||||
print(f"Failed to remove {p}: {e}")
|
||||
# Remove empty dirs
|
||||
for d in dirs:
|
||||
dp = os.path.join(root, d)
|
||||
try:
|
||||
if not os.listdir(dp):
|
||||
os.rmdir(dp)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user