From b24925ed9071641ec359ff07dcae668968692fe9 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 23 Nov 2022 19:21:21 +0100 Subject: [PATCH] Max length --- reddit/subreddit.py | 21 +++++++++++++++++++-- utils/.config.template.toml | 1 + utils/subreddit.py | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 13351c4..5c4b6a1 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -87,8 +87,25 @@ def get_subreddit_threads(POST_ID: str): threads = subreddit.hot(limit=25) submission = get_subreddit_undone(threads, subreddit) submission = check_done(submission) # double-checking - if submission is None or not submission.num_comments: - return get_subreddit_threads(POST_ID) # submission already done. rerun + if submission is None: + return get_subreddit_threads(POST_ID) # submission already done. rerun + + if settings.config["settings"]["storymode"]: + if not submission.selftext and settings.config["reddit"]["thread"]["post_id"] != "": + print_substep("You are trying to use story mode on post with no post text") + exit() + elif not submission.selftext: + print_substep("You are trying to use story mode on post with no post text") + return get_subreddit_threads(POST_ID) + else: + # Check for the length of the post text + if len(submission.selftext) > (settings.config["settings"]["storymode_max_length"] or 2000): + print_substep( + f"Post is too long ({len(submission.selftext)}), retrying with a different post. ({settings.config['settings']['storymode_max_length']} character limit)" + ) + return get_subreddit_threads(POST_ID) + elif not submission.num_comments: + return get_subreddit_threads(POST_ID) upvotes = submission.score ratio = submission.upvote_ratio * 100 num_comments = submission.num_comments diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 075c9c0..2ec32a5 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -24,6 +24,7 @@ opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" } storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, great for subreddits with stories" } storymodemethod= { optional = true, default = 1, example = 1, explanation = "Style that's used for the storymode. Set to 0 for single picture display in whole video, set to 1 for fancy looking video ", type = "int", nmin = 0, oob_error = "It's very hard to run something less than once.", options = [0, 1] } +storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } fps = { optional = false, default = 30, example = 30, explanation = "Sets the FPS of the video, 30 is default for best performance. 60 FPS is smoother.", type = "int", nmin = 1, nmax = 60, oob_error = "The FPS HAS to be between 1 and 60" } diff --git a/utils/subreddit.py b/utils/subreddit.py index 28121a6..3af1ffe 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -38,7 +38,7 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0): continue if submission.num_comments <= int( settings.config["reddit"]["thread"]["min_comments"] - ): + ) and not settings.config["settings"]["storymode"]: print_substep( f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...' )