Apply formatting

pull/2166/head
mvenus 11 months ago
parent ad6a8abfc9
commit 11477b3404

@ -16,7 +16,9 @@ def get_reddit_instance():
"""Initialize and return a Reddit instance.""" """Initialize and return a Reddit instance."""
print_substep("Logging into Reddit.") print_substep("Logging into Reddit.")
if settings.config["reddit"]["creds"]["2fa"]: if settings.config["reddit"]["creds"]["2fa"]:
print("\nEnter your two-factor authentication code from your authenticator app.\n") print(
"\nEnter your two-factor authentication code from your authenticator app.\n"
)
code = input("> ") code = input("> ")
print() print()
password = settings.config["reddit"]["creds"]["password"] password = settings.config["reddit"]["creds"]["password"]
@ -48,7 +50,9 @@ def get_subreddit(reddit):
"""Get the subreddit based on user input or config.""" """Get the subreddit based on user input or config."""
if not settings.config["reddit"]["thread"]["subreddit"]: if not settings.config["reddit"]["thread"]["subreddit"]:
try: try:
subreddit_name = sub(r"r\/", "", input("What subreddit would you like to pull from? ")) subreddit_name = sub(
r"r\/", "", input("What subreddit would you like to pull from? ")
)
return reddit.subreddit(subreddit_name) return reddit.subreddit(subreddit_name)
except ValueError: except ValueError:
print_substep("Subreddit not defined. Using AskReddit.") print_substep("Subreddit not defined. Using AskReddit.")
@ -66,15 +70,25 @@ def get_submission(reddit, subreddit, post_id):
if post_id: if post_id:
return reddit.submission(id=post_id) return reddit.submission(id=post_id)
if settings.config["reddit"]["thread"]["post_id"] and len(str(settings.config["reddit"]["thread"]["post_id"]).split("+")) == 1: if (
settings.config["reddit"]["thread"]["post_id"]
and len(str(settings.config["reddit"]["thread"]["post_id"]).split("+")) == 1
):
return reddit.submission(id=settings.config["reddit"]["thread"]["post_id"]) return reddit.submission(id=settings.config["reddit"]["thread"]["post_id"])
if settings.config["ai"]["ai_similarity_enabled"]: if settings.config["ai"]["ai_similarity_enabled"]:
threads = subreddit.hot(limit=50) threads = subreddit.hot(limit=50)
keywords = [keyword.strip() for keyword in settings.config["ai"]["ai_similarity_keywords"].split(",")] keywords = [
print(f"Sorting threads by similarity to the given keywords: {', '.join(keywords)}") keyword.strip()
for keyword in settings.config["ai"]["ai_similarity_keywords"].split(",")
]
print(
f"Sorting threads by similarity to the given keywords: {', '.join(keywords)}"
)
threads, similarity_scores = sort_by_similarity(threads, keywords) threads, similarity_scores = sort_by_similarity(threads, keywords)
return get_subreddit_undone(threads, subreddit, similarity_scores=similarity_scores) return get_subreddit_undone(
threads, subreddit, similarity_scores=similarity_scores
)
threads = subreddit.hot(limit=25) threads = subreddit.hot(limit=25)
return get_subreddit_undone(threads, subreddit) return get_subreddit_undone(threads, subreddit)
@ -92,14 +106,20 @@ def collect_comments(submission):
if not top_level_comment.stickied: if not top_level_comment.stickied:
sanitized_text = sanitize_text(top_level_comment.body) sanitized_text = sanitize_text(top_level_comment.body)
if sanitized_text and len(top_level_comment.body) <= int(settings.config["reddit"]["thread"]["max_comment_length"]): if sanitized_text and len(top_level_comment.body) <= int(
if len(top_level_comment.body) >= int(settings.config["reddit"]["thread"]["min_comment_length"]): settings.config["reddit"]["thread"]["max_comment_length"]
):
if len(top_level_comment.body) >= int(
settings.config["reddit"]["thread"]["min_comment_length"]
):
if top_level_comment.author is not None: if top_level_comment.author is not None:
comments.append({ comments.append(
{
"comment_body": top_level_comment.body, "comment_body": top_level_comment.body,
"comment_url": top_level_comment.permalink, "comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id, "comment_id": top_level_comment.id,
}) }
)
return comments return comments
@ -116,7 +136,10 @@ def get_subreddit_threads(post_id):
if submission is None: if submission is None:
return get_subreddit_threads(post_id) return get_subreddit_threads(post_id)
if not submission.num_comments and settings.config["settings"]["storymode"] == "false": if (
not submission.num_comments
and settings.config["settings"]["storymode"] == "false"
):
print_substep("No comments found. Skipping.") print_substep("No comments found. Skipping.")
exit() exit()

Loading…
Cancel
Save