From 30ebd6051caaadd8db47ea8c621858edb580b054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Budzy=C5=84ski?= Date: Thu, 9 Jun 2022 00:22:37 +0200 Subject: [PATCH 1/6] Video for Readme Closes !68 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 606b7db..5c2d886 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ The only original thing being done is the editing and gathering of all materials 6. Run `python3 main.py` 7. Enjoy 😎 +## Video +https://user-images.githubusercontent.com/19284904/172727335-7e11c816-3484-4033-a535-4b061751fa3b.mp4 + + ## Contributing & Ways to improve 📈 In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. From c028c73ace63f17338cad473d214dc173e621553 Mon Sep 17 00:00:00 2001 From: PatatjeMC Date: Thu, 9 Jun 2022 15:23:04 +0200 Subject: [PATCH 2/6] fixed a name thingy that gave errors get_hottest_undone did not exist anywhere in the code and so I think you accidentally typed the wrong thing --- reddit/subreddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index cc5bc02..efbee8a 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -5,7 +5,7 @@ import praw from utils.console import print_step, print_substep from utils.videos import check_done -from utils.subreddit import get_hottest_undone +from utils.subreddit import get_subreddit_undone TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890") @@ -60,7 +60,7 @@ def get_subreddit_threads(): submission = reddit.submission(id=getenv("POST_ID")) else: threads = subreddit.hot(limit=25) - submission = get_hottest_undone(threads) + submission = get_subreddit_undone(threads, subreddit) submission = check_done(submission) # double checking if submission is None: return get_subreddit_threads() # submission already done. rerun From 40134e02e89fbfa9b08d5aa4cacac5f22de69354 Mon Sep 17 00:00:00 2001 From: PatatjeMC Date: Thu, 9 Jun 2022 16:00:10 +0200 Subject: [PATCH 3/6] Better anti NSFW post Instead of looking at the screen to look if it's nsfw it checks it earlier so it doesn't have to create all the mp3's and open the browser to do it. Also it fixes some errors because of it cause playwright was being buggy with it for some reason. --- utils/subreddit.py | 6 ++++++ video_creation/screenshot_downloader.py | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/subreddit.py b/utils/subreddit.py index 4b82f2c..d5c1673 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -1,5 +1,7 @@ from typing import List import json +from os import getenv +from utils.console import print_substep def get_subreddit_undone(submissions: List, subreddit): """ @@ -10,6 +12,10 @@ def get_subreddit_undone(submissions: List, subreddit): for submission in submissions: if already_done(done_videos, submission): continue + if submission.over_18: + if getenv("ALLOW_NSFW").casefold() == "false": + print_substep("NSFW Post Detected. Skipping...") + continue return submission return get_subreddit_undone(subreddit.top(time_filter="hour"), subreddit) # all of the videos in hot have already been done diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index fda30f4..5271f27 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -40,12 +40,6 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. - if getenv("ALLOW_NSFW").casefold() == "false": - print_substep("NSFW Post Detected. Skipping...") - from main import main - - main() - print_substep("Post is NSFW. You are spicy... :fire:") page.locator('[data-testid="content-gate"] button').click() From 1d75172ac2a0fdd6417644b9683c264405b3a38d Mon Sep 17 00:00:00 2001 From: PatatjeMC Date: Thu, 9 Jun 2022 16:02:16 +0200 Subject: [PATCH 4/6] Revert "Better anti NSFW post" This reverts commit 40134e02e89fbfa9b08d5aa4cacac5f22de69354. --- utils/subreddit.py | 6 ------ video_creation/screenshot_downloader.py | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/subreddit.py b/utils/subreddit.py index d5c1673..4b82f2c 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -1,7 +1,5 @@ from typing import List import json -from os import getenv -from utils.console import print_substep def get_subreddit_undone(submissions: List, subreddit): """ @@ -12,10 +10,6 @@ def get_subreddit_undone(submissions: List, subreddit): for submission in submissions: if already_done(done_videos, submission): continue - if submission.over_18: - if getenv("ALLOW_NSFW").casefold() == "false": - print_substep("NSFW Post Detected. Skipping...") - continue return submission return get_subreddit_undone(subreddit.top(time_filter="hour"), subreddit) # all of the videos in hot have already been done diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 5271f27..fda30f4 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -40,6 +40,12 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. + if getenv("ALLOW_NSFW").casefold() == "false": + print_substep("NSFW Post Detected. Skipping...") + from main import main + + main() + print_substep("Post is NSFW. You are spicy... :fire:") page.locator('[data-testid="content-gate"] button').click() From aa384fd805ddc2dbc4bf388da0e47f0a02eae8fb Mon Sep 17 00:00:00 2001 From: PatatjeMC Date: Thu, 9 Jun 2022 16:02:19 +0200 Subject: [PATCH 5/6] Revert "fixed a name thingy that gave errors" This reverts commit c028c73ace63f17338cad473d214dc173e621553. --- reddit/subreddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index efbee8a..cc5bc02 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -5,7 +5,7 @@ import praw from utils.console import print_step, print_substep from utils.videos import check_done -from utils.subreddit import get_subreddit_undone +from utils.subreddit import get_hottest_undone TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890") @@ -60,7 +60,7 @@ def get_subreddit_threads(): submission = reddit.submission(id=getenv("POST_ID")) else: threads = subreddit.hot(limit=25) - submission = get_subreddit_undone(threads, subreddit) + submission = get_hottest_undone(threads) submission = check_done(submission) # double checking if submission is None: return get_subreddit_threads() # submission already done. rerun From 73b2a29f1ac0eca1a2ada98ff880b04072eac1c5 Mon Sep 17 00:00:00 2001 From: PatatjeMC Date: Thu, 9 Jun 2022 16:11:12 +0200 Subject: [PATCH 6/6] Better anti NSFW Instead of looking at the screen to look if it's nsfw it checks it earlier so it doesn't have to create all the mp3's and open the browser to do it. Also it fixes some errors because of it cause playwright was being buggy with it for some reason. --- utils/subreddit.py | 7 ++++++- video_creation/screenshot_downloader.py | 6 ------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/utils/subreddit.py b/utils/subreddit.py index 3fc1613..7a7dca0 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -1,6 +1,7 @@ from typing import List import json - +from os import getenv +from utils.console import print_substep def get_subreddit_undone(submissions: List, subreddit): """ @@ -11,6 +12,10 @@ def get_subreddit_undone(submissions: List, subreddit): for submission in submissions: if already_done(done_videos, submission): continue + if submission.over_18: + if getenv("ALLOW_NSFW").casefold() == "false": + print_substep("NSFW Post Detected. Skipping...") + continue return submission return get_subreddit_undone( subreddit.top(time_filter="hour"), subreddit diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 89d6728..d401811 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -42,12 +42,6 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. - if getenv("ALLOW_NSFW").casefold() == "false": - print_substep("NSFW Post Detected. Skipping...") - from main import main - - main() - print_substep("Post is NSFW. You are spicy... :fire:") page.locator('[data-testid="content-gate"] button').click()