From c935d865cae113902692996ab13a9c3bac5272ea Mon Sep 17 00:00:00 2001 From: liamb13 <69778531+liamb13@users.noreply.github.com> Date: Wed, 24 May 2023 11:13:42 +1000 Subject: [PATCH 1/2] Create playwright.py util file --- utils/playwright.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 utils/playwright.py diff --git a/utils/playwright.py b/utils/playwright.py new file mode 100644 index 0000000..be046e6 --- /dev/null +++ b/utils/playwright.py @@ -0,0 +1,7 @@ +def clear_cookie_by_name(context, cookie_cleared_name): + cookies = context.cookies() + filtered_cookies = [ + cookie for cookie in cookies if cookie["name"] != cookie_cleared_name + ] + context.clear_cookies() + context.add_cookies(filtered_cookies) From bd015a466a4c69f137551f663196a7c7fd4f6171 Mon Sep 17 00:00:00 2001 From: liamb13 <69778531+liamb13@users.noreply.github.com> Date: Wed, 24 May 2023 11:14:48 +1000 Subject: [PATCH 2/2] Update screenshot_downloader.py --- video_creation/screenshot_downloader.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 1c3ab5e..6948644 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -11,6 +11,7 @@ from rich.progress import track from utils import settings from utils.console import print_step, print_substep from utils.imagenarator import imagemaker +from utils.playwright import clear_cookie_by_name from utils.videos import save_data @@ -117,6 +118,13 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): page.wait_for_timeout(5000) page.wait_for_load_state() + # Handle the redesign + # Check if the redesign optout cookie is set + if page.locator("#redesign-beta-optin-btn").is_visible(): + # Clear the redesign optout cookie + clear_cookie_by_name(context, "redesign_optout") + # Reload the page for the redesign to take effect + page.reload() # Get the thread screenshot page.goto(reddit_object["thread_url"], timeout=0) page.set_viewport_size(ViewportSize(width=W, height=H))