Added cleanup in shutdown and fixed bug

pull/1091/head
Simon 3 years ago committed by GitHub
parent d11b177344
commit 566bda734f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

10
id.py

@ -0,0 +1,10 @@
import re
from utils.console import print_substep
def id(reddit_obj: dict):
"""
This function takes a reddit object and returns the post id
"""
id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
print_substep(f"Thread ID is {id}", style="bold blue")
return id

@ -9,7 +9,8 @@ from prawcore import ResponseException
from reddit.subreddit import get_subreddit_threads from reddit.subreddit import get_subreddit_threads
from utils.cleanup import cleanup from utils.cleanup import cleanup
from utils.console import print_markdown, print_step, print_substep from utils.console import print_markdown, print_step, print_substep
from utils import settings, id from utils import settings
from utils.id import id
from video_creation.background import ( from video_creation.background import (
download_background, download_background,
@ -42,7 +43,8 @@ print_step(f"You are using v{__VERSION__} of the bot in the {__BRANCH__} branch.
def main(POST_ID=None): def main(POST_ID=None):
reddit_object = get_subreddit_threads(POST_ID) reddit_object = get_subreddit_threads(POST_ID)
id(reddit_object) global redditid
redditid = id(reddit_object)
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
length = math.ceil(length) length = math.ceil(length)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
@ -62,9 +64,16 @@ def run_many(times):
def shutdown(): def shutdown():
print("Exiting...") print_markdown("## Clearing temp files")
exit() try:
redditid
except NameError:
print("Exiting...")
exit()
else:
cleanup(redditid)
print("Exiting...")
exit()
if __name__ == "__main__": if __name__ == "__main__":
config = settings.check_toml("utils/.config.template.toml", "config.toml") config = settings.check_toml("utils/.config.template.toml", "config.toml")

Loading…
Cancel
Save