improvements

pull/280/head
iaacornus 3 years ago
parent d6c7287630
commit 231a3497f5
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -9,7 +9,6 @@ from utils.console import print_step, print_substep
def get_subreddit_threads(subreddit_): def get_subreddit_threads(subreddit_):
global submission
""" """
Takes subreddit_ as parameter which defaults to None, but in this Takes subreddit_ as parameter which defaults to None, but in this
case since it is None, it would raise ValueError, thus defaulting 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. Returns a list of threads from the AskReddit subreddit.
""" """
global submission
load_dotenv() load_dotenv()
print_step("Getting AskReddit threads...") print_step("Getting AskReddit threads...")

@ -19,16 +19,16 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
# ! Make sure the reddit screenshots folder exists # ! Make sure the reddit screenshots folder exists
Path("assets/png").mkdir(parents=True, exist_ok=True) Path("assets/png").mkdir(parents=True, exist_ok=True)
with sync_playwright() as p: with sync_playwright() as browser_:
print_substep("Launching Headless Browser...") print_substep("Launching Headless Browser...")
browser = p.chromium.launch() browser = browser_.chromium.launch()
context = browser.new_context() context = browser.new_context()
if theme.casefold() == "dark": if theme.casefold() == "dark":
cookie_file = open("video_creation/cookies.json") with open("video_creation/cookies.json", encoding="utf-8") as cookie_file:
cookies = json.load(cookie_file) cookies = json.load(cookie_file)
context.add_cookies(cookies) context.add_cookies(cookies)
# Get the thread screenshot # Get the thread screenshot
page = context.new_page() page = context.new_page()
@ -45,8 +45,8 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
) )
for idx, comment in track( 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 # Stop if we have reached the screenshot_num
if idx >= screenshot_num: if idx >= screenshot_num:

Loading…
Cancel
Save