refactor: screenshot_downloader.py uses toml config

pull/861/head
Callum Leslie 2 years ago
parent 19ef71fc9a
commit ac04b665de
No known key found for this signature in database
GPG Key ID: D382C4AFEECEAA90

@ -1,9 +1,9 @@
import json import json
import os import os
from os import getenv
from pathlib import Path from pathlib import Path
from typing import Dict from typing import Dict
from utils import settings
from playwright.async_api import async_playwright # pylint: disable=unused-import from playwright.async_api import async_playwright # pylint: disable=unused-import
# do not remove the above line # do not remove the above line
@ -35,7 +35,7 @@ def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: in
browser = p.chromium.launch() browser = p.chromium.launch()
context = browser.new_context() context = browser.new_context()
if getenv("THEME").upper() == "DARK": if settings.config["settings"]["theme"] == "dark":
cookie_file = open("./video_creation/data/cookie-dark-mode.json", encoding="utf-8") cookie_file = open("./video_creation/data/cookie-dark-mode.json", encoding="utf-8")
else: else:
cookie_file = open("./video_creation/data/cookie-light-mode.json", encoding="utf-8") cookie_file = open("./video_creation/data/cookie-light-mode.json", encoding="utf-8")
@ -56,7 +56,7 @@ def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: in
# translate code # translate code
if getenv("POSTLANG"): if settings.config["reddit"]["thread"]["post_lang"]:
print_substep("Translating post...") print_substep("Translating post...")
texts_in_tl = ts.google(reddit_object["thread_title"], to_language=os.getenv("POSTLANG")) texts_in_tl = ts.google(reddit_object["thread_title"], to_language=os.getenv("POSTLANG"))
@ -88,9 +88,9 @@ def download_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: in
# translate code # translate code
if getenv("POSTLANG"): if settings.config["reddit"]["thread"]["post_lang"]:
comment_tl = ts.google( comment_tl = ts.google(
comment["comment_body"], to_language=os.getenv("POSTLANG") comment["comment_body"], to_language=settings.config["reddit"]["thread"]["post_lang"]
) )
page.evaluate( page.evaluate(
'([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content', '([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content',

Loading…
Cancel
Save