From 607e1fd451b96dc0b684fa17a9d992bc8ec6a813 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Sat, 23 Dec 2023 04:59:37 -0500 Subject: [PATCH 1/4] Update my discord --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81e37be..5fadd83 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed inf Elebumm (Lewis#6305) - https://github.com/elebumm (Founder) -Jason (JasonLovesDoggo#1904) - https://github.com/JasonLovesDoggo (Maintainer) +Jason (personality.json) - https://github.com/JasonLovesDoggo (Maintainer) Simon (OpenSourceSimon) - https://github.com/OpenSourceSimon From 5895c87e1bfccb3bc88f3f539db45b0bc8fa2427 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Sun, 28 Jan 2024 09:17:00 -0500 Subject: [PATCH 2/4] Update stale.yml --- .github/workflows/stale.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 3db14aa..9598a19 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -12,7 +12,7 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/stale@v4 + - uses: actions/stale@v9 id: stale-issue name: stale-issue with: @@ -31,7 +31,7 @@ jobs: ascending: true #debug-only: true - - uses: actions/stale@v4 + - uses: actions/stale@v9 id: stale-pr name: stale-pr with: From d4bed8d0bfef2adaeee9f4466c7708ca6a7c7994 Mon Sep 17 00:00:00 2001 From: Ali Abusaleh Date: Mon, 19 Feb 2024 22:53:27 +0100 Subject: [PATCH 3/4] fix the Timeout during the screenshots --- video_creation/screenshot_downloader.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index cdc8d61..550e126 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -75,7 +75,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): print_substep("Launching Headless Browser...") browser = p.chromium.launch( - headless=True + headless=False ) # headless=False will show the browser for debugging purposes # Device scale factor (or dsf for short) allows us to increase the resolution of the screenshots # When the dsf is 1, the width of the screenshot is 600 pixels @@ -99,7 +99,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): page.goto("https://www.reddit.com/login", timeout=0) page.set_viewport_size(ViewportSize(width=1920, height=1080)) page.wait_for_load_state() - page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"]) page.locator('[name="password"]').fill(settings.config["reddit"]["creds"]["password"]) page.locator("button[class$='m-full-width']").click() @@ -177,12 +176,12 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # zoom the body of the page page.evaluate("document.body.style.zoom=" + str(zoom)) # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom - location = page.locator('[data-test-id="post-content"]').bounding_box() + location = page.locator(f'#t3_{reddit_id}').bounding_box() for i in location: location[i] = float("{:.2f}".format(location[i] * zoom)) page.screenshot(clip=location, path=postcontentpath) else: - page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) + page.locator(f'#t3_{reddit_id}').screenshot(path=postcontentpath) except Exception as e: print_substep("Something went wrong!", style="red") resp = input( @@ -213,6 +212,8 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): "Downloading screenshots...", ) ): + print_substep(f"Downloading screenshot {idx + 1} of {screenshot_num}...") + print_substep(f"Comment: {comment['comment_body']}") # Stop if we have reached the screenshot_num if idx >= screenshot_num: break @@ -241,9 +242,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # zoom the body of the page page.evaluate("document.body.style.zoom=" + str(zoom)) # scroll comment into view - page.locator(f"#t1_{comment['comment_id']}").scroll_into_view_if_needed() + page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").scroll_into_view_if_needed() # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom - location = page.locator(f"#t1_{comment['comment_id']}").bounding_box() + location = page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").bounding_box() for i in location: location[i] = float("{:.2f}".format(location[i] * zoom)) page.screenshot( @@ -251,7 +252,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): path=f"assets/temp/{reddit_id}/png/comment_{idx}.png", ) else: - page.locator(f"#t1_{comment['comment_id']}").screenshot( + page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").screenshot( path=f"assets/temp/{reddit_id}/png/comment_{idx}.png" ) except TimeoutError: From 801ba573b9102c42e95e69def1aea65926afb532 Mon Sep 17 00:00:00 2001 From: Ali Abusaleh Date: Fri, 23 Feb 2024 16:01:18 +0100 Subject: [PATCH 4/4] add fallback, handle new UI for login --- video_creation/screenshot_downloader.py | 54 ++++++++++++++++++++----- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 550e126..ca211c7 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -99,9 +99,15 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): page.goto("https://www.reddit.com/login", timeout=0) page.set_viewport_size(ViewportSize(width=1920, height=1080)) page.wait_for_load_state() - page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"]) - page.locator('[name="password"]').fill(settings.config["reddit"]["creds"]["password"]) - page.locator("button[class$='m-full-width']").click() + if selector_exists(page, "input#login-username"): + + page.locator('input#login-username').fill(settings.config["reddit"]["creds"]["username"]) + page.locator('input#login-password').fill(settings.config["reddit"]["creds"]["password"]) + page.locator("div[slot='primaryButton'] button.login").click() + else: + page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"]) + page.locator('[name="password"]').fill(settings.config["reddit"]["creds"]["password"]) + page.locator("button[class$='m-full-width']").click() page.wait_for_timeout(5000) login_error_div = page.locator(".AnimatedForm__errorMessage").first @@ -176,12 +182,19 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # zoom the body of the page page.evaluate("document.body.style.zoom=" + str(zoom)) # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom - location = page.locator(f'#t3_{reddit_id}').bounding_box() + if selector_exists(page, '[data-test-id="post-content"]'): + location = page.locator('[data-test-id="post-content"]').bounding_box() + else: + location = page.locator(f'#t3_{reddit_id}').bounding_box() + for i in location: location[i] = float("{:.2f}".format(location[i] * zoom)) page.screenshot(clip=location, path=postcontentpath) else: - page.locator(f'#t3_{reddit_id}').screenshot(path=postcontentpath) + if selector_exists(page, '[data-test-id="post-content"]'): + page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) + else: + page.locator(f'#t3_{reddit_id}').screenshot(path=postcontentpath) except Exception as e: print_substep("Something went wrong!", style="red") resp = input( @@ -242,9 +255,13 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # zoom the body of the page page.evaluate("document.body.style.zoom=" + str(zoom)) # scroll comment into view - page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").scroll_into_view_if_needed() - # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom - location = page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").bounding_box() + if selector_exists(page, '[data-testid="comment"]'): + page.locator(f"#t1_{comment['comment_id']}").scroll_into_view_if_needed() + location = page.locator(f"#t1_{comment['comment_id']}").bounding_box() + else: + page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").scroll_into_view_if_needed() + # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom + location = page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").bounding_box() for i in location: location[i] = float("{:.2f}".format(location[i] * zoom)) page.screenshot( @@ -252,9 +269,14 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): path=f"assets/temp/{reddit_id}/png/comment_{idx}.png", ) else: - page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").screenshot( - path=f"assets/temp/{reddit_id}/png/comment_{idx}.png" - ) + if selector_exists(page, f"#t1_{comment['comment_id']}"): + page.locator(f"#t1_{comment['comment_id']}").screenshot( + path=f"assets/temp/{reddit_id}/png/comment_{idx}.png" + ) + else: + page.locator(f"#t1_{comment['comment_id']}-comment-rtjson-content").screenshot( + path=f"assets/temp/{reddit_id}/png/comment_{idx}.png" + ) except TimeoutError: del reddit_object["comments"] screenshot_num += 1 @@ -265,3 +287,13 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): browser.close() print_substep("Screenshots downloaded Successfully.", style="bold green") + + + + +def selector_exists(page, selector, timeout=3000): + try: + element = page.locator(selector).is_visible(timeout=timeout) + return element + except: + return False \ No newline at end of file