From 0b6ed0324f1762ad3a90c6bf34f8a020e864e4f7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 8 Jan 2023 22:23:02 +0000 Subject: [PATCH] Improve checking for content --- blocking.py | 6 +++--- content.py | 24 ++++++++++++------------ inbox.py | 14 +++++++------- outbox.py | 2 +- posts.py | 10 +++++----- utils.py | 4 ++-- video.py | 2 +- webapp_post.py | 8 ++++---- webapp_search.py | 2 +- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/blocking.py b/blocking.py index d4109d780..3f40d1884 100644 --- a/blocking.py +++ b/blocking.py @@ -1381,15 +1381,15 @@ def add_cw_from_lists(post_json_object: {}, cw_lists: {}, translate: {}, """ if not lists_enabled: return - if not post_json_object['object'].get('content'): - if not post_json_object['object'].get('contentMap'): + if 'content' not in post_json_object['object']: + if 'contentMap' not in post_json_object['object']: return cw_text = '' if post_json_object['object'].get('summary'): cw_text = post_json_object['object']['summary'] content = None - if post_json_object['object'].get('contentMap'): + if 'contentMap' in post_json_object['object']: if post_json_object['object']['contentMap'].get(system_language): content = \ post_json_object['object']['contentMap'][system_language] diff --git a/content.py b/content.py index da079d768..f1e4d5c84 100644 --- a/content.py +++ b/content.py @@ -2006,8 +2006,8 @@ def create_edits_html(edits_json: {}, post_json_object: {}, return '' if not has_object_dict(post_json_object): return '' - if not post_json_object['object'].get('content'): - if not post_json_object['object'].get('contentMap'): + if 'content' not in post_json_object['object']: + if 'contentMap' not in post_json_object['object']: return '' edit_dates_list = [] for modified, _ in edits_json.items(): @@ -2015,14 +2015,14 @@ def create_edits_html(edits_json: {}, post_json_object: {}, edit_dates_list.sort(reverse=True) edits_str = '' content = None - if post_json_object['object'].get('contentMap'): + if 'contentMap' in post_json_object['object']: if post_json_object['object']['contentMap'].get(system_language): content = \ post_json_object['object']['contentMap'][system_language] - if not content: - if post_json_object['object'].get('content'): + if content is None: + if 'content' in post_json_object['object']: content = post_json_object['object']['content'] - if not content: + if content is None: return '' content = remove_html(content) for modified in edit_dates_list: @@ -2030,17 +2030,17 @@ def create_edits_html(edits_json: {}, post_json_object: {}, if not has_object_dict(prev_json): continue prev_content = None - if not prev_json['object'].get('content'): - if not prev_json['object'].get('contentMap'): + if 'content' not in prev_json['object']: + if 'contentMap' not in prev_json['object']: continue - if prev_json['object'].get('contentMap'): + if 'contentMap' in prev_json['object']: if prev_json['object']['contentMap'].get(system_language): prev_content = \ prev_json['object']['contentMap'][system_language] - if not prev_content: - if prev_json['object'].get('content'): + if prev_content is None: + if 'content' in prev_json['object']: prev_content = prev_json['object']['content'] - if not prev_content: + if prev_content is None: continue prev_content = remove_html(prev_content) if content == prev_content: diff --git a/inbox.py b/inbox.py index afd1cfc5f..fff698f05 100644 --- a/inbox.py +++ b/inbox.py @@ -341,7 +341,7 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str, # get geolocations from content map_links = [] published = None - if post_json_object['object'].get('content'): + if 'content' in post_json_object['object']: published = post_json_object['object']['published'] post_content = post_json_object['object']['content'] map_links += get_map_links_from_post_content(post_content) @@ -1295,9 +1295,9 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {}, return False if not has_object_dict(post_json_object): return False - if not post_json_object['object'].get('content'): + if 'content' not in post_json_object['object']: return False - if not message_json['object'].get('content'): + if 'content' not in message_json['object']: return False # does the actor match? if post_json_object['actor'] != message_json['actor']: @@ -1776,7 +1776,7 @@ def _receive_reaction(recent_posts_cache: {}, return False if not has_object_string(message_json, debug): return False - if not message_json.get('content'): + if 'content' not in message_json: if debug: print('DEBUG: ' + message_json['type'] + ' has no "content"') return False @@ -1939,7 +1939,7 @@ def _receive_zot_reaction(recent_posts_cache: {}, return False if message_json['object']['type'] != 'Note': return False - if not message_json['object'].get('content'): + if 'content' not in message_json['object']: if debug: print('DEBUG: ' + message_json['object']['type'] + ' has no "content"') @@ -2119,7 +2119,7 @@ def _receive_undo_reaction(recent_posts_cache: {}, return False if not has_object_string_object(message_json, debug): return False - if not message_json['object'].get('content'): + if 'content' not in message_json['object']: if debug: print('DEBUG: ' + message_json['type'] + ' has no "content"') return False @@ -3012,7 +3012,7 @@ def _valid_post_content(base_dir: str, nickname: str, domain: str, """ if not has_object_dict(message_json): return True - if not message_json['object'].get('content'): + if 'content' not in message_json['object']: return True if not message_json['object'].get('published'): diff --git a/outbox.py b/outbox.py index 80088d450..8870096ea 100644 --- a/outbox.py +++ b/outbox.py @@ -207,7 +207,7 @@ def _capitalize_hashtag(content: str, message_json: {}, if '#' + original_tag not in content: return content = content.replace('#' + original_tag, '#' + capitalized_tag) - if message_json['object'].get('contentMap'): + if 'contentMap' in message_json['object']: if message_json['object']['contentMap'].get(system_language): message_json['object']['contentMap'][system_language] = content message_json['object']['contentMap'][system_language] = content diff --git a/posts.py b/posts.py index f6b11ca53..f1b0b13f6 100644 --- a/posts.py +++ b/posts.py @@ -5315,7 +5315,7 @@ def download_announce(session, base_dir: str, http_prefix: str, # Check the content of the announce content_str = announced_json['content'] using_content_map = False - if announced_json.get('contentMap'): + if 'contentMap' in announced_json: if announced_json['contentMap'].get(system_language): content_str = announced_json['contentMap'][system_language] using_content_map = True @@ -5879,7 +5879,7 @@ def edited_post_filename(base_dir: str, nickname: str, domain: str, return '', None if not post_json_object['object'].get('id'): return '', None - if not post_json_object['object'].get('content'): + if 'content' not in post_json_object['object']: return '', None if not post_json_object['object'].get('attributedTo'): return '', None @@ -5923,7 +5923,7 @@ def edited_post_filename(base_dir: str, nickname: str, domain: str, return '', None if not lastpost_json['object'].get('id'): return '', None - if not lastpost_json['object'].get('content'): + if 'content' not in lastpost_json['object']: return '', None if not lastpost_json['object'].get('attributedTo'): return '', None @@ -5937,12 +5937,12 @@ def edited_post_filename(base_dir: str, nickname: str, domain: str, if debug: print(post_id + ' might be an edit of ' + lastpost_id) lastpost_content = lastpost_json['object']['content'] - if lastpost_json['object'].get('contentMap'): + if 'contentMap' in lastpost_json['object']: if lastpost_json['object']['contentMap'].get(system_language): lastpost_content = \ lastpost_json['object']['contentMap'][system_language] content = post_json_object['object']['content'] - if post_json_object['object'].get('contentMap'): + if 'contentMap' in post_json_object['object']: if post_json_object['object']['contentMap'].get(system_language): content = \ post_json_object['object']['contentMap'][system_language] diff --git a/utils.py b/utils.py index 1babab2c9..a91995a71 100644 --- a/utils.py +++ b/utils.py @@ -287,7 +287,7 @@ def get_base_content_from_post(post_json_object: {}, this_post_json = post_json_object if has_object_dict(post_json_object): this_post_json = post_json_object['object'] - if not this_post_json.get('content'): + if 'content' not in this_post_json: return '' return this_post_json['content'] @@ -2571,7 +2571,7 @@ def is_blog_post(post_json_object: {}) -> bool: return False if not has_object_string_type(post_json_object, False): return False - if not post_json_object['object'].get('content'): + if 'content' not in post_json_object['object']: return False if post_json_object['object']['type'] != 'Article': return False diff --git a/video.py b/video.py index 7e86fb642..3a67e1de1 100644 --- a/video.py +++ b/video.py @@ -91,7 +91,7 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str, return None content += '

' + post_json_object['license']['name'] + '

' post_content = post_json_object['content'] - if post_json_object.get('contentMap'): + if 'contentMap' in post_json_object: if post_json_object['contentMap'].get(system_language): post_content = post_json_object['contentMap'][system_language] content += post_content diff --git a/webapp_post.py b/webapp_post.py index ab5594735..fc6da176d 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -158,9 +158,9 @@ def _html_post_metadata_open_graph(domain: str, post_json_object: {}, " \n" if not obj_json.get('attachment') or obj_json.get('sensitive'): - if obj_json.get('content') and not obj_json.get('sensitive'): + if 'content' in obj_json and not obj_json.get('sensitive'): obj_content = obj_json['content'] - if obj_json.get('contentMap'): + if 'contentMap' in obj_json: if obj_json['contentMap'].get(system_language): obj_content = obj_json['contentMap'][system_language] description = remove_html(obj_content) @@ -190,9 +190,9 @@ def _html_post_metadata_open_graph(domain: str, post_json_object: {}, elif attach_json['mediaType'].startswith('audio/'): description = 'Attached: 1 audio' if description: - if obj_json.get('content') and not obj_json.get('sensitive'): + if 'content' in obj_json and not obj_json.get('sensitive'): obj_content = obj_json['content'] - if obj_json.get('contentMap'): + if 'contentMap' in obj_json: if obj_json['contentMap'].get(system_language): obj_content = obj_json['contentMap'][system_language] description += '\n\n' + remove_html(obj_content) diff --git a/webapp_search.py b/webapp_search.py index b75cca5ff..70cb8e0a0 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -1333,7 +1333,7 @@ def rss_hashtag_search(nickname: str, domain: str, port: int, break continue # add to feed - if post_json_object['object'].get('content') and \ + if 'content' in post_json_object['object'] and \ post_json_object['object'].get('attributedTo') and \ post_json_object['object'].get('published'): published = post_json_object['object']['published']