From 08ee274dc8d2fc124570a09a3e7ae9f80d6a69dd Mon Sep 17 00:00:00 2001 From: tumpa02 Date: Mon, 22 Jan 2024 18:50:46 +0100 Subject: [PATCH] fix: fixed cleanup.py util not returning the number of deleted files fix: returned print statement in final_video.py to showcase the number of deleted files --- utils/cleanup.py | 8 +++++++- video_creation/final_video.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/cleanup.py b/utils/cleanup.py index 449eca3..ff3ddbc 100644 --- a/utils/cleanup.py +++ b/utils/cleanup.py @@ -14,7 +14,13 @@ def cleanup(reddit_id) -> int: int: How many files were deleted """ directory = f"assets/temp/{reddit_id}/" + deleted_files_count = 0 + if exists(directory): + # Count the number of files before deleting + for root, dirs, files in os.walk(directory): + deleted_files_count += len(files) + shutil.rmtree(directory) - return 1 + return deleted_files_count diff --git a/video_creation/final_video.py b/video_creation/final_video.py index ee20ef1..df4d207 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -441,6 +441,7 @@ def make_final_video( save_data(subreddit, filename + ".mp4", title, idx, background_config["video"][2]) print_step("Removing temporary files 🗑") - cleanup(reddit_id) + cleanups = cleanup(reddit_id) + print_substep(f"Removed {cleanups} temporary files 🗑") print_step("Done! 🎉 The video is in the results folder 📁") time.sleep(1) # Prevents the last 2 print_step functions from not showing up