Improve checking for content

main
Bob Mottram 2023-01-08 22:23:02 +00:00
parent 6aecffd75c
commit 0b6ed0324f
9 changed files with 36 additions and 36 deletions

View File

@ -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]

View File

@ -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:

View File

@ -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'):

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -91,7 +91,7 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
return None
content += '<p>' + post_json_object['license']['name'] + '</p>'
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

View File

@ -158,9 +158,9 @@ def _html_post_metadata_open_graph(domain: str, post_json_object: {},
" <meta content=\"" + obj_json['published'] + \
"\" property=\"og:published_time\" />\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)

View File

@ -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']