From 39d1aac958b459ffec57a2be50caf191ac3caaa1 Mon Sep 17 00:00:00 2001 From: Hey Moon Date: Sat, 7 May 2022 20:34:05 -0500 Subject: [PATCH] removing quoted text --- autodrama.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/autodrama.py b/autodrama.py index 4c9a791..cb13630 100644 --- a/autodrama.py +++ b/autodrama.py @@ -159,7 +159,7 @@ def analyze_comments(submission : 'Submission'): basedness = average_child_score - comment_score ranked_comments.append((basedness, comment_info)) # Add to angriness - score = sid_obj.polarity_scores(comment.body)['compound'] + score = sid_obj.polarity_scores(remove_quoted_text(comment.body))['compound'] if score < -0.5: angry_comments.append((sid_obj.polarity_scores(comment.body)['compound'], comment_info)) @@ -191,6 +191,9 @@ def analyze_comments(submission : 'Submission'): } #get_based_submissions("all", "hour", 25, True) +def remove_quoted_text(string): + return '\n'.join([i for i in string.split("\n") if i == "" or i[0] != ">"]) + def generate_comment_display_section(submissions : 'Tuple[float, Submission]', section_title, detail_display, number_to_show, show_details = True, detail_func = lambda a : a, max_len = 1000 ): markdown_lines = [] if len(submissions) != 0: @@ -204,7 +207,8 @@ def generate_comment_display_section(submissions : 'Tuple[float, Submission]', s comment_indent = "" if (parent != None): - parent_body = parent.body.replace("\n", "") + parent_body = remove_quoted_text(parent.body) + parent_body = parent_body.replace("\n", "") if len(parent_body) > max_len: parent_body = parent_body[0:max_len-3] + "..." markdown_lines.append(f"> {parent_body} ({parent.score})") @@ -212,7 +216,8 @@ def generate_comment_display_section(submissions : 'Tuple[float, Submission]', s else: comment_indent = ">" - comment_body = comment.body.replace("\n", "") + comment_body = remove_quoted_text(comment.body) + comment_body = comment_body.replace("\n", "") if len(comment_body) > max_len: comment_body = comment_body[0:max_len-3] + "..." markdown_lines.append(f"{comment_indent} [{comment_body}](https://reddit.com{comment.permalink}) ({comment.score})")