From 61b22077952c5bfdf227eed326bed098468f0abc Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 27 Jul 2022 10:13:30 +0100 Subject: [PATCH] Check for twitter content within announces --- content.py | 18 ++++++++++++++++++ inbox.py | 30 +++++++----------------------- posts.py | 12 +++++++++--- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/content.py b/content.py index 9ef638d44..e184df2aa 100644 --- a/content.py +++ b/content.py @@ -1941,3 +1941,21 @@ def remove_script(content: str, log_filename: str, print('EX: cannot append to svg script log') content = content.replace(text, '') return content + + +def reject_twitter_summary(base_dir: str, nickname: str, domain: str, + summary: str) -> bool: + """Returns true if the post should be rejected due to twitter + existing within the summary + """ + if not summary: + return False + remove_twitter = \ + acct_dir(base_dir, nickname, domain) + '/.removeTwitter' + if not os.path.isfile(remove_twitter): + return False + summary_lower = summary.lower() + if 'twitter' in summary_lower or \ + 'birdsite' in summary_lower: + return True + return False diff --git a/inbox.py b/inbox.py index db56a03e9..ea521a2cc 100644 --- a/inbox.py +++ b/inbox.py @@ -131,6 +131,7 @@ from conversation import update_conversation from webapp_hashtagswarm import html_hash_tag_swarm from person import valid_sending_actor from fitnessFunctions import fitness_performance +from content import reject_twitter_summary from content import load_dogwhistles from content import valid_url_lengths from content import remove_script @@ -567,22 +568,6 @@ def inbox_permitted_message(domain: str, message_json: {}, return True -def _reject_twitter_summary(base_dir: str, nickname: str, domain: str, - summary: str) -> bool: - """Returns true if the post should be rejected due to twitter - existing within the summary - """ - remove_twitter = \ - acct_dir(base_dir, nickname, domain) + '/.removeTwitter' - if not os.path.isfile(remove_twitter): - return False - summary_lower = summary.lower() - if 'twitter' in summary_lower or \ - 'birdsite' in summary_lower: - return True - return False - - def save_post_to_inbox_queue(base_dir: str, http_prefix: str, nickname: str, domain: str, post_json_object: {}, @@ -671,13 +656,12 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, if debug: print('WARN: post was filtered out due to content') return None - if summary_str: - if _reject_twitter_summary(base_dir, nickname, domain, - summary_str): - if debug: - print('WARN: post was filtered out due to ' + - 'twitter content') - return None + if reject_twitter_summary(base_dir, nickname, domain, + summary_str): + if debug: + print('WARN: post was filtered out due to ' + + 'twitter summary') + return None original_post_id = None if post_json_object.get('id'): diff --git a/posts.py b/posts.py index 58dbbca83..f65e97d1f 100644 --- a/posts.py +++ b/posts.py @@ -79,6 +79,7 @@ from media import get_music_metadata from media import attach_media from media import replace_you_tube from media import replace_twitter +from content import reject_twitter_summary from content import words_similarity from content import limit_repeated_words from content import post_tag_exists @@ -5026,15 +5027,20 @@ def download_announce(session, base_dir: str, http_prefix: str, base_dir, nickname, domain, post_id, recent_posts_cache) return None - + if reject_twitter_summary(base_dir, nickname, domain, + summary_str): + print('WARN: announced post has twitter summary ' + + str(announced_json)) + _reject_announce(announce_filename, + base_dir, nickname, domain, post_id, + recent_posts_cache) + return None if invalid_ciphertext(content_str): print('WARN: announced post contains invalid ciphertext ' + str(announced_json)) _reject_announce(announce_filename, base_dir, nickname, domain, post_id, recent_posts_cache) - print('WARN: Invalid ciphertext within announce ' + - str(announced_json)) return None # remove any long words