diff --git a/.config.template.toml b/.config.template.toml index ceb59c2..62a8c38 100644 --- a/.config.template.toml +++ b/.config.template.toml @@ -1,13 +1,13 @@ [reddit.creds] -client_id = { optional = false, example = "fFAGRNJru1FTz70BzhT3Zg", explanation = "the ID of your Reddit app of SCRIPT type", default = "", nmin = 12, nmax = 30, regex = "^[-a-zA-Z0-9._~+/]+=*$", oob_error = "The ID should be over 12 and under 30 characters, double check your input.", input_error = "The client ID can only contain printable characters." } -client_secret = { optional = false, example = "fFAGRNJru1FTz70BzhT3Zg", explanation = "the SECRET of your Reddit app of SCRIPT type", default = "", nmin = 20, nmax = 40, regex = "^[-a-zA-Z0-9._~+/]+=*$", oob_error = "The secret should be over 20 and under 40 characters, double check your input.", input_error = "The client ID can only contain printable characters." } -username = { optional = false, example = "JasonLovesDoggo", explanation = "the username of your reddit account", default = "", nmin = 3, nmax = 20,regex = "^[-_0-9a-zA-Z]+$", oob_error = "A username HAS to be between 3 and 20 characters" } -password = { optional = false, example = "fFAGRNJru1FTz70BzhT3Zg", explanation = "the password of your reddit account", default = "", nmin = 8, oob_error = "Password too short" } +client_id = { optional = false, example = "fFAGRNJru1FTz70BzhT3Zg", explanation = "the ID of your Reddit app of SCRIPT type", nmin = 12, nmax = 30, regex = "^[-a-zA-Z0-9._~+/]+=*$", oob_error = "The ID should be over 12 and under 30 characters, double check your input.", input_error = "The client ID can only contain printable characters." } +client_secret = { optional = false, example = "fFAGRNJru1FTz70BzhT3Zg", explanation = "the SECRET of your Reddit app of SCRIPT type", nmin = 20, nmax = 40, regex = "^[-a-zA-Z0-9._~+/]+=*$", oob_error = "The secret should be over 20 and under 40 characters, double check your input.", input_error = "The client ID can only contain printable characters." } +username = { optional = false, example = "JasonLovesDoggo", explanation = "the username of your reddit account", nmin = 3, nmax = 20,regex = "^[-_0-9a-zA-Z]+$", oob_error = "A username HAS to be between 3 and 20 characters" } +password = { optional = false, example = "fFAGRNJru1FTz70BzhT3Zg", explanation = "the password of your reddit account", nmin = 8, oob_error = "Password too short" } 2fa = { optional = true, example = "True", explanation = "Whether you have Reddit 2FA enabled, Valid options are True and False", default = false, options = [true, false], type = "bool" } [reddit.thread] random = { optional = true, example = "True", explanation = "If set to false, it will ask you a thread link to extract the thread, if true it will randomize it.", default = true, options = [true, false], type = "bool" } -subreddit = { optional = false, example = "AskReddit", explanation = "what subreddit to pull posts from, the name of the sub, not the URL", default = "", nmin = 3, nmax = 21,regex = "[_0-9a-zA-Z]+$", oob_error = "A subreddit name HAS to be between 3 and 20 characters" } +subreddit = { optional = false, example = "AskReddit", explanation = "what subreddit to pull posts from, the name of the sub, not the URL", default = "askreddit", nmin = 3, nmax = 21,regex = "[_0-9a-zA-Z]+$", oob_error = "A subreddit name HAS to be between 3 and 20 characters" } post_id = { optional = true, example = "urdtfx", explanation = "Used if you want to use a specific post.", regex = "^((?!://|://)[+a-zA-Z])*$" } max_comment_length = { optional = false, example = 500, explanation = "max number of characters a comment can have. default is 500", default = 500, type = "int", nmin = 10, nmax = 10000, oob_error = "the max comment length should be between 10 and 10000" } post_lang = { optional = true, example = "es-cr", explanation = "The language you would like to translate to.", default = "" } diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c807df1..6351d7a 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -66,27 +66,28 @@ def get_subreddit_threads(POST_ID: str): and len(settings.config["reddit"]["thread"]["post_id"].split("+")) == 1): submission = reddit.submission(id=settings.config["reddit"]["thread"]["post_id"]) - comment_type = settings.config["reddit"]["thread"]["sort"] - + sort_type = settings.config["reddit"]["thread"]["sort"] + sort_time = settings.config["reddit"]["thread"]["sort_time"] try: - if str(comment_type) == "top": - threads = subreddit.top(limit=25) - elif str(comment_type) == "new": - threads = subreddit.new(limit=25) - elif str(comment_type) == "hot": - threads = subreddit.hot(limit=25) - elif str(comment_type) == "relevance": - threads = subreddit.relevance(limit=25) + if str(sort_type) == "top": + threads = subreddit.top(time_filter=sort_time, limit=25) + elif str(sort_type) == "new": + threads = subreddit.new(time_filter=sort_time, limit=25) + elif str(sort_type) == "hot": + threads = subreddit.hot(time_filter=sort_time, limit=25) + elif str(sort_type) == "relevance": + threads = subreddit.relevance(time_filter=sort_time, limit=25) else: - threads = subreddit.top(limit=25) + threads = subreddit.top(time_filter="all", limit=25) except AttributeError: - threads = subreddit.top(limit=25) + threads = subreddit.top(time_filter="all", 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 + submission.comment_sort = "top" upvotes = submission.score ratio = submission.upvote_ratio * 100 num_comments = submission.num_comments