From f8c340f612201be87dc17886ce2c20c308cd2acc Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 1 Jun 2022 16:21:08 -0400 Subject: [PATCH] feat: added dark mode screenshots closes #13 --- .env.template | 1 + video_creation/data/cookie.json | 8 ++++++++ video_creation/screenshot_downloader.py | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 video_creation/data/cookie.json diff --git a/.env.template b/.env.template index df9b261..3cd9dd4 100644 --- a/.env.template +++ b/.env.template @@ -5,3 +5,4 @@ REDDIT_PASSWORD="" SUBREDDIT="AskReddit" ALLOW_NSFW="False" POST_ID="" +THEME="LIGHT" diff --git a/video_creation/data/cookie.json b/video_creation/data/cookie.json new file mode 100644 index 0000000..2e4e116 --- /dev/null +++ b/video_creation/data/cookie.json @@ -0,0 +1,8 @@ +[ + { + "name": "USER", + "value": "eyJwcmVmcyI6eyJ0b3BDb250ZW50RGlzbWlzc2FsVGltZSI6MCwiZ2xvYmFsVGhlbWUiOiJSRURESVQiLCJuaWdodG1vZGUiOnRydWUsImNvbGxhcHNlZFRyYXlTZWN0aW9ucyI6eyJmYXZvcml0ZXMiOmZhbHNlLCJtdWx0aXMiOmZhbHNlLCJtb2RlcmF0aW5nIjpmYWxzZSwic3Vic2NyaXB0aW9ucyI6ZmFsc2UsInByb2ZpbGVzIjpmYWxzZX0sInRvcENvbnRlbnRUaW1lc0Rpc21pc3NlZCI6MH19", + "domain": ".reddit.com", + "path": "/" + } +] diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 9023d82..12ea28d 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,3 +1,4 @@ +import json from os import getenv from playwright.sync_api import sync_playwright @@ -22,9 +23,14 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): print_substep("Launching Headless Browser...") browser = p.chromium.launch() + context = browser.new_context() + if getenv("THEME").upper() == "DARK": + cookie_file = open('./video_creation/data/cookie.json') + cookies = json.load(cookie_file) + context.add_cookies(cookies) # Get the thread screenshot - page = browser.new_page() + page = context.new_page() page.goto(reddit_object["thread_url"]) if page.locator('[data-testid="content-gate"]').is_visible():