diff --git a/webdriver/playwright.py b/webdriver/playwright.py index b9bd0fb..c4be81f 100644 --- a/webdriver/playwright.py +++ b/webdriver/playwright.py @@ -244,6 +244,7 @@ class RedditScreenshot(Flaky, Browser): to_language=self.post_lang, ) split_story_tl = story_tl.split('\n') + await main_page.evaluate( # Find all elements with story text "const elements = document.querySelectorAll('[data-test-id=\"post-content\"]" @@ -280,7 +281,7 @@ class RedditScreenshot(Flaky, Browser): Path("assets/temp/png").mkdir(parents=True, exist_ok=True) # Get the thread screenshot - reddit_main = await self.browser.new_page() + reddit_main = await self.context.new_page() # noinspection Duplicates await reddit_main.goto(self.reddit_object["thread_url"]) @@ -292,11 +293,11 @@ class RedditScreenshot(Flaky, Browser): await self.__close_nsfw(reddit_main) # Translates submission title - if settings.config["reddit"]["thread"]["post_lang"]: + if self.post_lang: print_substep("Translating post...") texts_in_tl = ts.google( self.reddit_object["thread_title"], - to_language=settings.config["reddit"]["thread"]["post_lang"], + to_language=self.post_lang, ) await reddit_main.evaluate( @@ -306,7 +307,7 @@ class RedditScreenshot(Flaky, Browser): else: print_substep("Skipping translation...") - # No sense to move it in common.py + # No sense to move it to common.py # noinspection Duplicates async_tasks_primary = ( [ diff --git a/webdriver/pyppeteer.py b/webdriver/pyppeteer.py index b2c1e2a..7afc957 100644 --- a/webdriver/pyppeteer.py +++ b/webdriver/pyppeteer.py @@ -283,6 +283,7 @@ class RedditScreenshot(Browser, Wait): to_language=self.post_lang, ) split_story_tl = story_tl.split('\n') + await main_page.evaluate( # Find all elements with story text "const elements = document.querySelectorAll('[data-test-id=\"post-content\"]" @@ -331,11 +332,11 @@ class RedditScreenshot(Browser, Wait): await self.__close_nsfw(reddit_main) # Translates submission title - if settings.config["reddit"]["thread"]["post_lang"]: + if self.post_lang: print_substep("Translating post...") texts_in_tl = ts.google( self.reddit_object["thread_title"], - to_language=settings.config["reddit"]["thread"]["post_lang"], + to_language=self.post_lang, ) await reddit_main.evaluate( @@ -345,7 +346,7 @@ class RedditScreenshot(Browser, Wait): else: print_substep("Skipping translation...") - # No sense to move it in common.py + # No sense to move it to common.py # noinspection Duplicates async_tasks_primary = ( [