Files
RedditVideoMakerBot/utils/cleanup.py
T
SimonandCallum Leslie 5a8db46178 Bot can run multiple instances at the same time (#1091)
* Bot can run multiple instances at the same time

* Delete TTS/__pycache__ directory

* Delete video_creation/__pycache__ directory

* Delete videos.json

* Delete utils/__pycache__ directory

* Create videos.json

* Moved id to utils

* Added cleanup in shutdown and fixed bug

* Removed watermark todo and fixed it

* Delete final_video.py

* Update final_video.py

* Delete video.py

* Update video.py

* Delete id.py

* feat: meaningful error message for bad credentials

* chore: remove comment reference to .env

Co-authored-by: Callum Leslie <git@cleslie.uk>
2022-08-09 20:48:15 +00:00

30 lines
804 B
Python

import os
from os.path import exists
def _listdir(d): # listdir with full path
return [os.path.join(d, f) for f in os.listdir(d)]
def cleanup(id) -> int:
"""Deletes all temporary assets in assets/temp
Returns:
int: How many files were deleted
"""
if exists("./assets/temp"):
count = 0
files = [f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower()]
count += len(files)
for f in files:
os.remove(f)
REMOVE_DIRS = [f"./assets/temp/{id}/mp3/", f"./assets/temp/{id}/png/"]
files_to_remove = list(map(_listdir, REMOVE_DIRS))
for directory in files_to_remove:
for file in directory:
count += 1
os.remove(file)
return count
return 0