from os import chdir, path, listdir, stat, remove, sep from datetime import timedelta from time import time from fhost import app chdir(path.dirname(path.abspath(__file__)) + sep + app.config["FHOST_STORAGE_PATH"]) max_content_len = app.config["MAX_CONTENT_LENGTH"] min_days = app.config['MIN_DAYS'] max_days = app.config['MAX_DAYS'] current_file = time() for file in listdir('.'): file_stat = stat(file) age = timedelta(seconds=current_file - file_stat.st_mtime).days maxage = min_days + (-max_days + min_days) * (file_stat.st_size / max_content_len - 1) ** 3 if age >= maxage: remove(file) print('Deleting file: {}, age: {}'.format(file, age))