refine subreddit search by timeframe

pull/915/head
anthony lloyd 3 years ago
parent d90ec538ec
commit b7dc54ebaf

@ -1,13 +1,13 @@
[reddit.creds] [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_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", 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." } 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", default = "", nmin = 3, nmax = 20,regex = "^[-_0-9a-zA-Z]+$", oob_error = "A username HAS to be between 3 and 20 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", default = "", nmin = 8, oob_error = "Password too short" } 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" } 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] [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" } 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])*$" } 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" } 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 = "" } post_lang = { optional = true, example = "es-cr", explanation = "The language you would like to translate to.", default = "" }

@ -66,27 +66,28 @@ def get_subreddit_threads(POST_ID: str):
and len(settings.config["reddit"]["thread"]["post_id"].split("+")) == 1): and len(settings.config["reddit"]["thread"]["post_id"].split("+")) == 1):
submission = reddit.submission(id=settings.config["reddit"]["thread"]["post_id"]) 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: try:
if str(comment_type) == "top": if str(sort_type) == "top":
threads = subreddit.top(limit=25) threads = subreddit.top(time_filter=sort_time, limit=25)
elif str(comment_type) == "new": elif str(sort_type) == "new":
threads = subreddit.new(limit=25) threads = subreddit.new(time_filter=sort_time, limit=25)
elif str(comment_type) == "hot": elif str(sort_type) == "hot":
threads = subreddit.hot(limit=25) threads = subreddit.hot(time_filter=sort_time, limit=25)
elif str(comment_type) == "relevance": elif str(sort_type) == "relevance":
threads = subreddit.relevance(limit=25) threads = subreddit.relevance(time_filter=sort_time, limit=25)
else: else:
threads = subreddit.top(limit=25) threads = subreddit.top(time_filter="all", limit=25)
except AttributeError: except AttributeError:
threads = subreddit.top(limit=25) threads = subreddit.top(time_filter="all", limit=25)
submission = get_subreddit_undone(threads, subreddit) submission = get_subreddit_undone(threads, subreddit)
submission = check_done(submission) # double-checking submission = check_done(submission) # double-checking
if submission is None or not submission.num_comments: if submission is None or not submission.num_comments:
return get_subreddit_threads(POST_ID) # submission already done. rerun return get_subreddit_threads(POST_ID) # submission already done. rerun
submission.comment_sort = "top"
upvotes = submission.score upvotes = submission.score
ratio = submission.upvote_ratio * 100 ratio = submission.upvote_ratio * 100
num_comments = submission.num_comments num_comments = submission.num_comments

Loading…
Cancel
Save