diff --git a/reddit/subreddit.py b/reddit/subreddit.py index d549bb7..be85874 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -9,7 +9,6 @@ from utils.console import print_step, print_substep def get_subreddit_threads(subreddit_): - global submission """ Takes subreddit_ as parameter which defaults to None, but in this case since it is None, it would raise ValueError, thus defaulting @@ -18,6 +17,7 @@ def get_subreddit_threads(subreddit_): Returns a list of threads from the AskReddit subreddit. """ + global submission load_dotenv() print_step("Getting AskReddit threads...") diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 72b65ff..c7d9abd 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -19,16 +19,16 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): # ! Make sure the reddit screenshots folder exists Path("assets/png").mkdir(parents=True, exist_ok=True) - with sync_playwright() as p: + with sync_playwright() as browser_: print_substep("Launching Headless Browser...") - browser = p.chromium.launch() + browser = browser_.chromium.launch() context = browser.new_context() if theme.casefold() == "dark": - cookie_file = open("video_creation/cookies.json") - cookies = json.load(cookie_file) - context.add_cookies(cookies) + with open("video_creation/cookies.json", encoding="utf-8") as cookie_file: + cookies = json.load(cookie_file) + context.add_cookies(cookies) # Get the thread screenshot page = context.new_page() @@ -45,8 +45,8 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): ) for idx, comment in track( - enumerate(reddit_object["comments"]), "Downloading screenshots..." - ): + enumerate(reddit_object["comments"]), "Downloading screenshots..." + ): # Stop if we have reached the screenshot_num if idx >= screenshot_num: