mirror of https://gitlab.com/bashrc2/epicyon
json loading retries may not be needed
parent
4708a8df8c
commit
9dd546b85c
|
@ -343,7 +343,7 @@ def _save_custom_emoji(session, base_dir: str, emoji_name: str, url: str,
|
||||||
emoji_json_filename = custom_emoji_dir + '/emoji.json'
|
emoji_json_filename = custom_emoji_dir + '/emoji.json'
|
||||||
emoji_json = {}
|
emoji_json = {}
|
||||||
if os.path.isfile(emoji_json_filename):
|
if os.path.isfile(emoji_json_filename):
|
||||||
emoji_json = load_json(emoji_json_filename, 0, 1)
|
emoji_json = load_json(emoji_json_filename)
|
||||||
if not emoji_json:
|
if not emoji_json:
|
||||||
emoji_json = {}
|
emoji_json = {}
|
||||||
if not emoji_json.get(emoji_name):
|
if not emoji_json.get(emoji_name):
|
||||||
|
@ -2001,7 +2001,7 @@ def import_emoji(base_dir: str, import_filename: str, session) -> None:
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile(import_filename):
|
if not os.path.isfile(import_filename):
|
||||||
return
|
return
|
||||||
emoji_dict = load_json(base_dir + '/emoji/default_emoji.json', 0, 1)
|
emoji_dict = load_json(base_dir + '/emoji/default_emoji.json')
|
||||||
added = 0
|
added = 0
|
||||||
with open(import_filename, "r", encoding='utf-8') as fp_emoji:
|
with open(import_filename, "r", encoding='utf-8') as fp_emoji:
|
||||||
lines = fp_emoji.readlines()
|
lines = fp_emoji.readlines()
|
||||||
|
|
|
@ -26,7 +26,7 @@ def load_cw_lists(base_dir: str, verbose: bool) -> {}:
|
||||||
continue
|
continue
|
||||||
list_filename = os.path.join(base_dir + '/cwlists', fname)
|
list_filename = os.path.join(base_dir + '/cwlists', fname)
|
||||||
print('list_filename: ' + list_filename)
|
print('list_filename: ' + list_filename)
|
||||||
list_json = load_json(list_filename, 0, 1)
|
list_json = load_json(list_filename)
|
||||||
if not list_json:
|
if not list_json:
|
||||||
continue
|
continue
|
||||||
if not list_json.get('name'):
|
if not list_json.get('name'):
|
||||||
|
|
|
@ -658,7 +658,7 @@ def daemon_http_get(self) -> None:
|
||||||
actor_filename = acct_dir(self.server.base_dir, nickname,
|
actor_filename = acct_dir(self.server.base_dir, nickname,
|
||||||
self.server.domain) + '.json'
|
self.server.domain) + '.json'
|
||||||
if os.path.isfile(actor_filename):
|
if os.path.isfile(actor_filename):
|
||||||
actor_json = load_json(actor_filename, 1, 1)
|
actor_json = load_json(actor_filename)
|
||||||
if not actor_json:
|
if not actor_json:
|
||||||
print('DEBUG: shareditems 2 ' + actor)
|
print('DEBUG: shareditems 2 ' + actor)
|
||||||
http_404(self, 114)
|
http_404(self, 114)
|
||||||
|
|
|
@ -745,7 +745,7 @@ def like_button(self, calling_domain: str, path: str,
|
||||||
liked_post_filename = \
|
liked_post_filename = \
|
||||||
locate_post(base_dir, self.post_to_nickname, domain, like_url)
|
locate_post(base_dir, self.post_to_nickname, domain, like_url)
|
||||||
if liked_post_filename:
|
if liked_post_filename:
|
||||||
liked_post_json = load_json(liked_post_filename, 0, 1)
|
liked_post_json = load_json(liked_post_filename)
|
||||||
if orig_filename and orig_post_url:
|
if orig_filename and orig_post_url:
|
||||||
update_likes_collection(recent_posts_cache,
|
update_likes_collection(recent_posts_cache,
|
||||||
base_dir, liked_post_filename,
|
base_dir, liked_post_filename,
|
||||||
|
@ -1000,7 +1000,7 @@ def like_button_undo(self, calling_domain: str, path: str,
|
||||||
liked_post_filename = locate_post(base_dir, self.post_to_nickname,
|
liked_post_filename = locate_post(base_dir, self.post_to_nickname,
|
||||||
domain, like_url)
|
domain, like_url)
|
||||||
if liked_post_filename:
|
if liked_post_filename:
|
||||||
liked_post_json = load_json(liked_post_filename, 0, 1)
|
liked_post_json = load_json(liked_post_filename)
|
||||||
if orig_filename and orig_post_url:
|
if orig_filename and orig_post_url:
|
||||||
undo_likes_collection_entry(recent_posts_cache,
|
undo_likes_collection_entry(recent_posts_cache,
|
||||||
base_dir, liked_post_filename,
|
base_dir, liked_post_filename,
|
||||||
|
@ -1264,7 +1264,7 @@ def reaction_button(self, calling_domain: str, path: str,
|
||||||
locate_post(base_dir, self.post_to_nickname, domain,
|
locate_post(base_dir, self.post_to_nickname, domain,
|
||||||
reaction_url)
|
reaction_url)
|
||||||
if reaction_post_filename:
|
if reaction_post_filename:
|
||||||
reaction_post_json = load_json(reaction_post_filename, 0, 1)
|
reaction_post_json = load_json(reaction_post_filename)
|
||||||
if orig_filename and orig_post_url:
|
if orig_filename and orig_post_url:
|
||||||
update_reaction_collection(recent_posts_cache,
|
update_reaction_collection(recent_posts_cache,
|
||||||
base_dir, reaction_post_filename,
|
base_dir, reaction_post_filename,
|
||||||
|
@ -1544,7 +1544,7 @@ def reaction_button_undo(self, calling_domain: str, path: str,
|
||||||
locate_post(base_dir, self.post_to_nickname, domain,
|
locate_post(base_dir, self.post_to_nickname, domain,
|
||||||
reaction_url)
|
reaction_url)
|
||||||
if reaction_post_filename:
|
if reaction_post_filename:
|
||||||
reaction_post_json = load_json(reaction_post_filename, 0, 1)
|
reaction_post_json = load_json(reaction_post_filename)
|
||||||
if orig_filename and orig_post_url:
|
if orig_filename and orig_post_url:
|
||||||
undo_reaction_collection_entry(recent_posts_cache,
|
undo_reaction_collection_entry(recent_posts_cache,
|
||||||
base_dir,
|
base_dir,
|
||||||
|
@ -1762,7 +1762,7 @@ def bookmark_button(self, calling_domain: str, path: str,
|
||||||
locate_post(base_dir, self.post_to_nickname, domain, bookmark_url)
|
locate_post(base_dir, self.post_to_nickname, domain, bookmark_url)
|
||||||
if bookmark_filename:
|
if bookmark_filename:
|
||||||
print('Regenerating html post for changed bookmark')
|
print('Regenerating html post for changed bookmark')
|
||||||
bookmark_post_json = load_json(bookmark_filename, 0, 1)
|
bookmark_post_json = load_json(bookmark_filename)
|
||||||
if bookmark_post_json:
|
if bookmark_post_json:
|
||||||
cached_post_filename = \
|
cached_post_filename = \
|
||||||
get_cached_post_filename(base_dir, self.post_to_nickname,
|
get_cached_post_filename(base_dir, self.post_to_nickname,
|
||||||
|
@ -1973,7 +1973,7 @@ def bookmark_button_undo(self, calling_domain: str, path: str,
|
||||||
locate_post(base_dir, self.post_to_nickname, domain, bookmark_url)
|
locate_post(base_dir, self.post_to_nickname, domain, bookmark_url)
|
||||||
if bookmark_filename:
|
if bookmark_filename:
|
||||||
print('Regenerating html post for changed unbookmark')
|
print('Regenerating html post for changed unbookmark')
|
||||||
bookmark_post_json = load_json(bookmark_filename, 0, 1)
|
bookmark_post_json = load_json(bookmark_filename)
|
||||||
if bookmark_post_json:
|
if bookmark_post_json:
|
||||||
cached_post_filename = \
|
cached_post_filename = \
|
||||||
get_cached_post_filename(base_dir, self.post_to_nickname,
|
get_cached_post_filename(base_dir, self.post_to_nickname,
|
||||||
|
@ -2283,7 +2283,7 @@ def mute_button(self, calling_domain: str, path: str,
|
||||||
locate_post(base_dir, nickname, domain, mute_url)
|
locate_post(base_dir, nickname, domain, mute_url)
|
||||||
if mute_filename:
|
if mute_filename:
|
||||||
print('mute_post: Regenerating html post for changed mute status')
|
print('mute_post: Regenerating html post for changed mute status')
|
||||||
mute_post_json = load_json(mute_filename, 0, 1)
|
mute_post_json = load_json(mute_filename)
|
||||||
if mute_post_json:
|
if mute_post_json:
|
||||||
cached_post_filename = \
|
cached_post_filename = \
|
||||||
get_cached_post_filename(base_dir, nickname,
|
get_cached_post_filename(base_dir, nickname,
|
||||||
|
@ -2456,7 +2456,7 @@ def mute_button_undo(self, calling_domain: str, path: str,
|
||||||
if mute_filename:
|
if mute_filename:
|
||||||
print('unmute_post: ' +
|
print('unmute_post: ' +
|
||||||
'Regenerating html post for changed unmute status')
|
'Regenerating html post for changed unmute status')
|
||||||
mute_post_json = load_json(mute_filename, 0, 1)
|
mute_post_json = load_json(mute_filename)
|
||||||
if mute_post_json:
|
if mute_post_json:
|
||||||
cached_post_filename = \
|
cached_post_filename = \
|
||||||
get_cached_post_filename(base_dir, nickname,
|
get_cached_post_filename(base_dir, nickname,
|
||||||
|
|
|
@ -1520,7 +1520,7 @@ def _receive_new_post_process_newshare(self, fields: {},
|
||||||
actor_filename = \
|
actor_filename = \
|
||||||
acct_dir(base_dir, nickname, domain) + '.json'
|
acct_dir(base_dir, nickname, domain) + '.json'
|
||||||
if os.path.isfile(actor_filename):
|
if os.path.isfile(actor_filename):
|
||||||
actor_json = load_json(actor_filename, 1, 1)
|
actor_json = load_json(actor_filename)
|
||||||
if actor_json:
|
if actor_json:
|
||||||
if add_shares_to_actor(base_dir, nickname, domain,
|
if add_shares_to_actor(base_dir, nickname, domain,
|
||||||
actor_json,
|
actor_json,
|
||||||
|
|
|
@ -190,7 +190,7 @@ def remove_share(self, calling_domain: str, cookie: str,
|
||||||
acct_dir(base_dir, share_nickname,
|
acct_dir(base_dir, share_nickname,
|
||||||
share_domain) + '.json'
|
share_domain) + '.json'
|
||||||
if os.path.isfile(actor_filename):
|
if os.path.isfile(actor_filename):
|
||||||
actor_json = load_json(actor_filename, 1, 1)
|
actor_json = load_json(actor_filename)
|
||||||
if actor_json:
|
if actor_json:
|
||||||
if add_shares_to_actor(base_dir,
|
if add_shares_to_actor(base_dir,
|
||||||
share_nickname, share_domain,
|
share_nickname, share_domain,
|
||||||
|
|
26
inbox.py
26
inbox.py
|
@ -1388,7 +1388,7 @@ def _receive_update_to_question(recent_posts_cache: {}, message_json: {},
|
||||||
if not post_filename:
|
if not post_filename:
|
||||||
return False
|
return False
|
||||||
# load the json for the question
|
# load the json for the question
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return False
|
return False
|
||||||
if not post_json_object.get('actor'):
|
if not post_json_object.get('actor'):
|
||||||
|
@ -1695,7 +1695,7 @@ def _receive_edit_to_post(recent_posts_cache: {}, message_json: {},
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# load the json for the original post
|
# load the json for the original post
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return False
|
return False
|
||||||
if not post_json_object.get('actor'):
|
if not post_json_object.get('actor'):
|
||||||
|
@ -1728,7 +1728,7 @@ def _receive_edit_to_post(recent_posts_cache: {}, message_json: {},
|
||||||
post_history_filename = post_filename.replace('.json', '') + '.edits'
|
post_history_filename = post_filename.replace('.json', '') + '.edits'
|
||||||
post_history_json = {}
|
post_history_json = {}
|
||||||
if os.path.isfile(post_history_filename):
|
if os.path.isfile(post_history_filename):
|
||||||
post_history_json = load_json(post_history_filename, 1)
|
post_history_json = load_json(post_history_filename)
|
||||||
# get the updated or published date
|
# get the updated or published date
|
||||||
if post_json_object['object'].get('updated'):
|
if post_json_object['object'].get('updated'):
|
||||||
published_str = post_json_object['object']['updated']
|
published_str = post_json_object['object']['updated']
|
||||||
|
@ -2188,7 +2188,7 @@ def _receive_like(recent_posts_cache: {},
|
||||||
post_liked_id, like_actor,
|
post_liked_id, like_actor,
|
||||||
handle_name, domain, debug, None)
|
handle_name, domain, debug, None)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
liked_post_json = load_json(post_filename, 0, 1)
|
liked_post_json = load_json(post_filename)
|
||||||
if liked_post_json:
|
if liked_post_json:
|
||||||
if liked_post_json.get('type'):
|
if liked_post_json.get('type'):
|
||||||
if liked_post_json['type'] == 'Announce' and \
|
if liked_post_json['type'] == 'Announce' and \
|
||||||
|
@ -2317,7 +2317,7 @@ def _receive_undo_like(recent_posts_cache: {},
|
||||||
undo_likes_collection_entry(recent_posts_cache, base_dir, post_filename,
|
undo_likes_collection_entry(recent_posts_cache, base_dir, post_filename,
|
||||||
like_actor, domain, debug, None)
|
like_actor, domain, debug, None)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
liked_post_json = load_json(post_filename, 0, 1)
|
liked_post_json = load_json(post_filename)
|
||||||
if liked_post_json:
|
if liked_post_json:
|
||||||
if liked_post_json.get('type'):
|
if liked_post_json.get('type'):
|
||||||
if liked_post_json['type'] == 'Announce' and \
|
if liked_post_json['type'] == 'Announce' and \
|
||||||
|
@ -2473,7 +2473,7 @@ def _receive_reaction(recent_posts_cache: {},
|
||||||
post_reaction_id, reaction_actor,
|
post_reaction_id, reaction_actor,
|
||||||
handle_name, domain, debug, None, emoji_content)
|
handle_name, domain, debug, None, emoji_content)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
reaction_post_json = load_json(post_filename, 0, 1)
|
reaction_post_json = load_json(post_filename)
|
||||||
if reaction_post_json:
|
if reaction_post_json:
|
||||||
if reaction_post_json.get('type'):
|
if reaction_post_json.get('type'):
|
||||||
if reaction_post_json['type'] == 'Announce' and \
|
if reaction_post_json['type'] == 'Announce' and \
|
||||||
|
@ -2659,7 +2659,7 @@ def _receive_zot_reaction(recent_posts_cache: {},
|
||||||
post_reaction_id, reaction_actor,
|
post_reaction_id, reaction_actor,
|
||||||
handle_name, domain, debug, None, emoji_content)
|
handle_name, domain, debug, None, emoji_content)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
reaction_post_json = load_json(post_filename, 0, 1)
|
reaction_post_json = load_json(post_filename)
|
||||||
if reaction_post_json:
|
if reaction_post_json:
|
||||||
if reaction_post_json.get('type'):
|
if reaction_post_json.get('type'):
|
||||||
if reaction_post_json['type'] == 'Announce' and \
|
if reaction_post_json['type'] == 'Announce' and \
|
||||||
|
@ -2804,7 +2804,7 @@ def _receive_undo_reaction(recent_posts_cache: {},
|
||||||
reaction_actor, domain,
|
reaction_actor, domain,
|
||||||
debug, None, emoji_content)
|
debug, None, emoji_content)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
reaction_post_json = load_json(post_filename, 0, 1)
|
reaction_post_json = load_json(post_filename)
|
||||||
if reaction_post_json:
|
if reaction_post_json:
|
||||||
if reaction_post_json.get('type'):
|
if reaction_post_json.get('type'):
|
||||||
if reaction_post_json['type'] == 'Announce' and \
|
if reaction_post_json['type'] == 'Announce' and \
|
||||||
|
@ -2950,7 +2950,7 @@ def _receive_bookmark(recent_posts_cache: {},
|
||||||
update_bookmarks_collection(recent_posts_cache, base_dir, post_filename,
|
update_bookmarks_collection(recent_posts_cache, base_dir, post_filename,
|
||||||
message_url2, actor_url, domain, debug)
|
message_url2, actor_url, domain, debug)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
bookmarked_post_json = load_json(post_filename, 0, 1)
|
bookmarked_post_json = load_json(post_filename)
|
||||||
if bookmarked_post_json:
|
if bookmarked_post_json:
|
||||||
if debug:
|
if debug:
|
||||||
cached_post_filename = \
|
cached_post_filename = \
|
||||||
|
@ -3078,7 +3078,7 @@ def _receive_undo_bookmark(recent_posts_cache: {},
|
||||||
post_filename,
|
post_filename,
|
||||||
actor_url, domain, debug)
|
actor_url, domain, debug)
|
||||||
# regenerate the html
|
# regenerate the html
|
||||||
bookmarked_post_json = load_json(post_filename, 0, 1)
|
bookmarked_post_json = load_json(post_filename)
|
||||||
if bookmarked_post_json:
|
if bookmarked_post_json:
|
||||||
if debug:
|
if debug:
|
||||||
cached_post_filename = \
|
cached_post_filename = \
|
||||||
|
@ -3811,7 +3811,7 @@ def _already_liked(base_dir: str, nickname: str, domain: str,
|
||||||
locate_post(base_dir, nickname, domain, post_url)
|
locate_post(base_dir, nickname, domain, post_url)
|
||||||
if not post_filename:
|
if not post_filename:
|
||||||
return False
|
return False
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return False
|
return False
|
||||||
if not has_object_dict(post_json_object):
|
if not has_object_dict(post_json_object):
|
||||||
|
@ -3841,7 +3841,7 @@ def _already_reacted(base_dir: str, nickname: str, domain: str,
|
||||||
locate_post(base_dir, nickname, domain, post_url)
|
locate_post(base_dir, nickname, domain, post_url)
|
||||||
if not post_filename:
|
if not post_filename:
|
||||||
return False
|
return False
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return False
|
return False
|
||||||
if not has_object_dict(post_json_object):
|
if not has_object_dict(post_json_object):
|
||||||
|
@ -6352,7 +6352,7 @@ def run_inbox_queue(server,
|
||||||
print('Loading queue item ' + queue_filename)
|
print('Loading queue item ' + queue_filename)
|
||||||
|
|
||||||
# Load the queue json
|
# Load the queue json
|
||||||
queue_json = load_json(queue_filename, 1)
|
queue_json = load_json(queue_filename)
|
||||||
fitness_performance(inbox_start_time, server.fitness,
|
fitness_performance(inbox_start_time, server.fitness,
|
||||||
'INBOX', 'load_queue_json', debug)
|
'INBOX', 'load_queue_json', debug)
|
||||||
inbox_start_time = time.time()
|
inbox_start_time = time.time()
|
||||||
|
|
|
@ -36,7 +36,7 @@ def _meta_data_instance_v1(show_accounts: bool,
|
||||||
if not os.path.isfile(admin_actor_filename):
|
if not os.path.isfile(admin_actor_filename):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
admin_actor = load_json(admin_actor_filename, 0)
|
admin_actor = load_json(admin_actor_filename)
|
||||||
if not admin_actor:
|
if not admin_actor:
|
||||||
print('WARN: json load exception _meta_data_instance_v1')
|
print('WARN: json load exception _meta_data_instance_v1')
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -43,7 +43,7 @@ def _meta_data_instance_v2(show_accounts: bool,
|
||||||
if not os.path.isfile(admin_actor_filename):
|
if not os.path.isfile(admin_actor_filename):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
admin_actor = load_json(admin_actor_filename, 0)
|
admin_actor = load_json(admin_actor_filename)
|
||||||
if not admin_actor:
|
if not admin_actor:
|
||||||
print('WARN: json load exception _meta_data_instance_v1')
|
print('WARN: json load exception _meta_data_instance_v1')
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -2281,7 +2281,7 @@ def get_account_pub_key(path: str, person_cache: {},
|
||||||
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
|
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
|
||||||
if not os.path.isfile(actor_filename):
|
if not os.path.isfile(actor_filename):
|
||||||
return None
|
return None
|
||||||
actor_json = load_json(actor_filename, 1, 1)
|
actor_json = load_json(actor_filename)
|
||||||
if not actor_json:
|
if not actor_json:
|
||||||
return None
|
return None
|
||||||
store_person_in_cache(base_dir, actor, actor_json,
|
store_person_in_cache(base_dir, actor, actor_json,
|
||||||
|
|
10
posts.py
10
posts.py
|
@ -4576,7 +4576,7 @@ def _passed_newswire_voting(newswire_votes_threshold: int,
|
||||||
if not votes_filename:
|
if not votes_filename:
|
||||||
return True
|
return True
|
||||||
# load the votes file and count the votes
|
# load the votes file and count the votes
|
||||||
votes_json = load_json(votes_filename, 0, 2)
|
votes_json = load_json(votes_filename)
|
||||||
if not votes_json:
|
if not votes_json:
|
||||||
return True
|
return True
|
||||||
if not positive_voting:
|
if not positive_voting:
|
||||||
|
@ -5070,7 +5070,7 @@ def _novel_fields_for_person(nickname: str, domain: str,
|
||||||
full_filename = os.path.join(box_dir, post_filename)
|
full_filename = os.path.join(box_dir, post_filename)
|
||||||
if not os.path.isfile(full_filename):
|
if not os.path.isfile(full_filename):
|
||||||
continue
|
continue
|
||||||
post_json_object = load_json(full_filename, 0, 1)
|
post_json_object = load_json(full_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
continue
|
continue
|
||||||
if not has_object_dict(post_json_object):
|
if not has_object_dict(post_json_object):
|
||||||
|
@ -6758,7 +6758,7 @@ def edited_post_filename(base_dir: str, nickname: str, domain: str,
|
||||||
locate_post(base_dir, nickname, domain, lastpost_id, False)
|
locate_post(base_dir, nickname, domain, lastpost_id, False)
|
||||||
if not lastpost_filename:
|
if not lastpost_filename:
|
||||||
return '', None
|
return '', None
|
||||||
lastpost_json = load_json(lastpost_filename, 0)
|
lastpost_json = load_json(lastpost_filename)
|
||||||
if not lastpost_json:
|
if not lastpost_json:
|
||||||
return '', None
|
return '', None
|
||||||
if not lastpost_json.get('type'):
|
if not lastpost_json.get('type'):
|
||||||
|
@ -6815,7 +6815,7 @@ def get_original_post_from_announce_url(announce_url: str, base_dir: str,
|
||||||
post_filename = locate_post(base_dir, nickname, domain, announce_url)
|
post_filename = locate_post(base_dir, nickname, domain, announce_url)
|
||||||
if not post_filename:
|
if not post_filename:
|
||||||
return None, None, None
|
return None, None, None
|
||||||
announce_post_json = load_json(post_filename, 0, 1)
|
announce_post_json = load_json(post_filename)
|
||||||
if not announce_post_json:
|
if not announce_post_json:
|
||||||
return None, None, post_filename
|
return None, None, post_filename
|
||||||
if not announce_post_json.get('type'):
|
if not announce_post_json.get('type'):
|
||||||
|
@ -6832,7 +6832,7 @@ def get_original_post_from_announce_url(announce_url: str, base_dir: str,
|
||||||
orig_filename = locate_post(base_dir, nickname, domain, orig_post_id)
|
orig_filename = locate_post(base_dir, nickname, domain, orig_post_id)
|
||||||
if orig_filename:
|
if orig_filename:
|
||||||
# we have the original post
|
# we have the original post
|
||||||
orig_post_json = load_json(orig_filename, 0, 1)
|
orig_post_json = load_json(orig_filename)
|
||||||
if orig_post_json:
|
if orig_post_json:
|
||||||
if has_object_dict(orig_post_json):
|
if has_object_dict(orig_post_json):
|
||||||
if orig_post_json['object'].get('attributedTo'):
|
if orig_post_json['object'].get('attributedTo'):
|
||||||
|
|
|
@ -268,7 +268,7 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
|
||||||
actor_filename = base_dir + '/cache/actors/' + actors_dict[handle]
|
actor_filename = base_dir + '/cache/actors/' + actors_dict[handle]
|
||||||
if not os.path.isfile(actor_filename):
|
if not os.path.isfile(actor_filename):
|
||||||
continue
|
continue
|
||||||
actor_json = load_json(actor_filename, 1, 1)
|
actor_json = load_json(actor_filename)
|
||||||
if not actor_json:
|
if not actor_json:
|
||||||
continue
|
continue
|
||||||
if not actor_json.get('movedTo'):
|
if not actor_json.get('movedTo'):
|
||||||
|
|
18
shares.py
18
shares.py
|
@ -337,7 +337,7 @@ def add_share(base_dir: str,
|
||||||
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
|
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
|
||||||
shares_json = {}
|
shares_json = {}
|
||||||
if os.path.isfile(shares_filename):
|
if os.path.isfile(shares_filename):
|
||||||
shares_json = load_json(shares_filename, 1, 2)
|
shares_json = load_json(shares_filename)
|
||||||
|
|
||||||
duration = duration.lower()
|
duration = duration.lower()
|
||||||
published = int(time.time())
|
published = int(time.time())
|
||||||
|
@ -469,7 +469,7 @@ def _expire_shares_for_account(base_dir: str, nickname: str, domain: str,
|
||||||
acct_handle_dir(base_dir, handle) + '/' + shares_file_type + '.json'
|
acct_handle_dir(base_dir, handle) + '/' + shares_file_type + '.json'
|
||||||
if not os.path.isfile(shares_filename):
|
if not os.path.isfile(shares_filename):
|
||||||
return 0
|
return 0
|
||||||
shares_json = load_json(shares_filename, 1, 2)
|
shares_json = load_json(shares_filename)
|
||||||
if not shares_json:
|
if not shares_json:
|
||||||
return 0
|
return 0
|
||||||
curr_time = int(time.time())
|
curr_time = int(time.time())
|
||||||
|
@ -1323,7 +1323,7 @@ def shares_catalog_account_endpoint(base_dir: str, http_prefix: str,
|
||||||
print(shares_file_type + '.json file not found: ' +
|
print(shares_file_type + '.json file not found: ' +
|
||||||
shares_filename)
|
shares_filename)
|
||||||
return endpoint
|
return endpoint
|
||||||
shares_json = load_json(shares_filename, 1, 2)
|
shares_json = load_json(shares_filename)
|
||||||
if not shares_json:
|
if not shares_json:
|
||||||
if debug:
|
if debug:
|
||||||
print('Unable to load json for ' + shares_filename)
|
print('Unable to load json for ' + shares_filename)
|
||||||
|
@ -1419,7 +1419,7 @@ def shares_catalog_endpoint(base_dir: str, http_prefix: str,
|
||||||
if not os.path.isfile(shares_filename):
|
if not os.path.isfile(shares_filename):
|
||||||
continue
|
continue
|
||||||
print('Test 78363 ' + shares_filename)
|
print('Test 78363 ' + shares_filename)
|
||||||
shares_json = load_json(shares_filename, 1, 2)
|
shares_json = load_json(shares_filename)
|
||||||
if not shares_json:
|
if not shares_json:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1511,7 +1511,7 @@ def generate_shared_item_federation_tokens(shared_items_federated_domains: [],
|
||||||
tokens_filename = \
|
tokens_filename = \
|
||||||
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
|
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
|
||||||
if os.path.isfile(tokens_filename):
|
if os.path.isfile(tokens_filename):
|
||||||
tokens_json = load_json(tokens_filename, 1, 2)
|
tokens_json = load_json(tokens_filename)
|
||||||
if tokens_json is None:
|
if tokens_json is None:
|
||||||
tokens_json = {}
|
tokens_json = {}
|
||||||
|
|
||||||
|
@ -1544,7 +1544,7 @@ def update_shared_item_federation_token(base_dir: str,
|
||||||
if os.path.isfile(tokens_filename):
|
if os.path.isfile(tokens_filename):
|
||||||
if debug:
|
if debug:
|
||||||
print('Update loading tokens for ' + token_domain_full)
|
print('Update loading tokens for ' + token_domain_full)
|
||||||
tokens_json = load_json(tokens_filename, 1, 2)
|
tokens_json = load_json(tokens_filename)
|
||||||
if tokens_json is None:
|
if tokens_json is None:
|
||||||
tokens_json = {}
|
tokens_json = {}
|
||||||
update_required = False
|
update_required = False
|
||||||
|
@ -1602,7 +1602,7 @@ def create_shared_item_federation_token(base_dir: str,
|
||||||
tokens_filename = \
|
tokens_filename = \
|
||||||
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
|
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
|
||||||
if os.path.isfile(tokens_filename):
|
if os.path.isfile(tokens_filename):
|
||||||
tokens_json = load_json(tokens_filename, 1, 2)
|
tokens_json = load_json(tokens_filename)
|
||||||
if tokens_json is None:
|
if tokens_json is None:
|
||||||
tokens_json = {}
|
tokens_json = {}
|
||||||
if force or not tokens_json.get(token_domain_full):
|
if force or not tokens_json.get(token_domain_full):
|
||||||
|
@ -1652,7 +1652,7 @@ def authorize_shared_items(shared_items_federated_domains: [],
|
||||||
print('DEBUG: shared item federation tokens file missing ' +
|
print('DEBUG: shared item federation tokens file missing ' +
|
||||||
tokens_filename)
|
tokens_filename)
|
||||||
return False
|
return False
|
||||||
tokens_json = load_json(tokens_filename, 1, 2)
|
tokens_json = load_json(tokens_filename)
|
||||||
if not tokens_json:
|
if not tokens_json:
|
||||||
return False
|
return False
|
||||||
if not tokens_json.get(calling_domain_full):
|
if not tokens_json.get(calling_domain_full):
|
||||||
|
@ -1878,7 +1878,7 @@ def run_federated_shares_daemon(base_dir: str, httpd, http_prefix: str,
|
||||||
if not os.path.isfile(tokens_filename):
|
if not os.path.isfile(tokens_filename):
|
||||||
time.sleep(file_check_interval_sec)
|
time.sleep(file_check_interval_sec)
|
||||||
continue
|
continue
|
||||||
tokens_json = load_json(tokens_filename, 1, 2)
|
tokens_json = load_json(tokens_filename)
|
||||||
if not tokens_json:
|
if not tokens_json:
|
||||||
time.sleep(file_check_interval_sec)
|
time.sleep(file_check_interval_sec)
|
||||||
continue
|
continue
|
||||||
|
|
10
tests.py
10
tests.py
|
@ -1508,7 +1508,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
for name in os.listdir(inbox_path):
|
for name in os.listdir(inbox_path):
|
||||||
filename = os.path.join(inbox_path, name)
|
filename = os.path.join(inbox_path, name)
|
||||||
assert os.path.isfile(filename)
|
assert os.path.isfile(filename)
|
||||||
received_json = load_json(filename, 0)
|
received_json = load_json(filename)
|
||||||
if received_json:
|
if received_json:
|
||||||
pprint(received_json['object']['content'])
|
pprint(received_json['object']['content'])
|
||||||
assert received_json
|
assert received_json
|
||||||
|
@ -1577,7 +1577,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
alice_post_json = load_json(outbox_post_filename, 0)
|
alice_post_json = load_json(outbox_post_filename)
|
||||||
if alice_post_json:
|
if alice_post_json:
|
||||||
pprint(alice_post_json)
|
pprint(alice_post_json)
|
||||||
|
|
||||||
|
@ -1602,7 +1602,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
alice_post_json = load_json(outbox_post_filename, 0)
|
alice_post_json = load_json(outbox_post_filename)
|
||||||
if alice_post_json:
|
if alice_post_json:
|
||||||
pprint(alice_post_json)
|
pprint(alice_post_json)
|
||||||
|
|
||||||
|
@ -3391,7 +3391,7 @@ def test_client_to_server(base_dir: str):
|
||||||
status_number = name.split('#statuses#')[1].replace('.json', '')
|
status_number = name.split('#statuses#')[1].replace('.json', '')
|
||||||
status_number = int(status_number.replace('#activity', ''))
|
status_number = int(status_number.replace('#activity', ''))
|
||||||
outbox_post_filename = outbox_path + '/' + name
|
outbox_post_filename = outbox_path + '/' + name
|
||||||
post_json_object = load_json(outbox_post_filename, 0)
|
post_json_object = load_json(outbox_post_filename)
|
||||||
if post_json_object:
|
if post_json_object:
|
||||||
outbox_post_id = remove_id_ending(post_json_object['id'])
|
outbox_post_id = remove_id_ending(post_json_object['id'])
|
||||||
assert outbox_post_id
|
assert outbox_post_id
|
||||||
|
@ -4039,7 +4039,7 @@ def _test_json_string() -> None:
|
||||||
"content": message_str
|
"content": message_str
|
||||||
}
|
}
|
||||||
assert save_json(test_json, filename)
|
assert save_json(test_json, filename)
|
||||||
received_json = load_json(filename, 0)
|
received_json = load_json(filename)
|
||||||
assert received_json
|
assert received_json
|
||||||
assert received_json['content'] == message_str
|
assert received_json['content'] == message_str
|
||||||
encoded_str = json.dumps(test_json, ensure_ascii=False)
|
encoded_str = json.dumps(test_json, ensure_ascii=False)
|
||||||
|
|
18
theme.py
18
theme.py
|
@ -176,7 +176,7 @@ def _set_theme_in_config(base_dir: str, name: str) -> bool:
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if not os.path.isfile(config_filename):
|
if not os.path.isfile(config_filename):
|
||||||
return False
|
return False
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if not config_json:
|
if not config_json:
|
||||||
return False
|
return False
|
||||||
config_json['theme'] = name
|
config_json['theme'] = name
|
||||||
|
@ -189,7 +189,7 @@ def _set_newswire_publish_as_icon(base_dir: str, use_icon: bool) -> bool:
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if not os.path.isfile(config_filename):
|
if not os.path.isfile(config_filename):
|
||||||
return False
|
return False
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if not config_json:
|
if not config_json:
|
||||||
return False
|
return False
|
||||||
config_json['showPublishAsIcon'] = use_icon
|
config_json['showPublishAsIcon'] = use_icon
|
||||||
|
@ -203,7 +203,7 @@ def _set_icons_as_buttons(base_dir: str, use_buttons: bool) -> bool:
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if not os.path.isfile(config_filename):
|
if not os.path.isfile(config_filename):
|
||||||
return False
|
return False
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if not config_json:
|
if not config_json:
|
||||||
return False
|
return False
|
||||||
config_json['iconsAsButtons'] = use_buttons
|
config_json['iconsAsButtons'] = use_buttons
|
||||||
|
@ -216,7 +216,7 @@ def _set_rss_icon_at_top(base_dir: str, at_top: bool) -> bool:
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if not os.path.isfile(config_filename):
|
if not os.path.isfile(config_filename):
|
||||||
return False
|
return False
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if not config_json:
|
if not config_json:
|
||||||
return False
|
return False
|
||||||
config_json['rssIconAtTop'] = at_top
|
config_json['rssIconAtTop'] = at_top
|
||||||
|
@ -230,7 +230,7 @@ def _set_publish_button_at_top(base_dir: str, at_top: bool) -> bool:
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if not os.path.isfile(config_filename):
|
if not os.path.isfile(config_filename):
|
||||||
return False
|
return False
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if not config_json:
|
if not config_json:
|
||||||
return False
|
return False
|
||||||
config_json['publishButtonAtTop'] = at_top
|
config_json['publishButtonAtTop'] = at_top
|
||||||
|
@ -245,7 +245,7 @@ def _set_full_width_timeline_button_header(base_dir: str,
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if not os.path.isfile(config_filename):
|
if not os.path.isfile(config_filename):
|
||||||
return False
|
return False
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if not config_json:
|
if not config_json:
|
||||||
return False
|
return False
|
||||||
config_json['fullWidthTlButtonHeader'] = full_width
|
config_json['fullWidthTlButtonHeader'] = full_width
|
||||||
|
@ -257,7 +257,7 @@ def get_theme(base_dir: str) -> str:
|
||||||
"""
|
"""
|
||||||
config_filename = base_dir + '/config.json'
|
config_filename = base_dir + '/config.json'
|
||||||
if os.path.isfile(config_filename):
|
if os.path.isfile(config_filename):
|
||||||
config_json = load_json(config_filename, 0)
|
config_json = load_json(config_filename)
|
||||||
if config_json:
|
if config_json:
|
||||||
if config_json.get('theme'):
|
if config_json.get('theme'):
|
||||||
return config_json['theme']
|
return config_json['theme']
|
||||||
|
@ -590,14 +590,14 @@ def _read_variables_file(base_dir: str, theme_name: str,
|
||||||
system_language: str) -> None:
|
system_language: str) -> None:
|
||||||
"""Reads variables from a file in the theme directory
|
"""Reads variables from a file in the theme directory
|
||||||
"""
|
"""
|
||||||
theme_params = load_json(variables_file, 0)
|
theme_params = load_json(variables_file)
|
||||||
if not theme_params:
|
if not theme_params:
|
||||||
return
|
return
|
||||||
|
|
||||||
# set custom theme parameters
|
# set custom theme parameters
|
||||||
custom_variables_file = data_dir(base_dir) + '/theme.json'
|
custom_variables_file = data_dir(base_dir) + '/theme.json'
|
||||||
if os.path.isfile(custom_variables_file):
|
if os.path.isfile(custom_variables_file):
|
||||||
custom_theme_params = load_json(custom_variables_file, 0)
|
custom_theme_params = load_json(custom_variables_file)
|
||||||
if custom_theme_params:
|
if custom_theme_params:
|
||||||
for variable_name, value in custom_theme_params.items():
|
for variable_name, value in custom_theme_params.items():
|
||||||
theme_params[variable_name] = value
|
theme_params[variable_name] = value
|
||||||
|
|
53
utils.py
53
utils.py
|
@ -1317,40 +1317,33 @@ def save_json(json_object: {}, filename: str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def load_json(filename: str, delay_sec: int = 2, max_tries: int = 5) -> {}:
|
def load_json(filename: str) -> {}:
|
||||||
"""Makes a few attempts to load a json formatted file
|
"""Makes a few attempts to load a json formatted file
|
||||||
"""
|
"""
|
||||||
if '/Actor@' in filename:
|
if '/Actor@' in filename:
|
||||||
filename = filename.replace('/Actor@', '/inbox@')
|
filename = filename.replace('/Actor@', '/inbox@')
|
||||||
|
|
||||||
json_object = None
|
json_object = None
|
||||||
tries = 1
|
data = None
|
||||||
while tries <= max_tries:
|
|
||||||
data = None
|
|
||||||
|
|
||||||
# load from file
|
# load from file
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r', encoding='utf-8') as json_file:
|
with open(filename, 'r', encoding='utf-8') as json_file:
|
||||||
data = json_file.read()
|
data = json_file.read()
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
print('EX: load_json exception ' +
|
print('EX: load_json exception ' + str(filename) + ' ' + str(exc))
|
||||||
str(tries) + ' ' + str(filename) + ' ' + str(exc))
|
return json_object
|
||||||
break
|
|
||||||
|
|
||||||
# check that something was loaded
|
# check that something was loaded
|
||||||
if not data:
|
if not data:
|
||||||
print('EX: load_json no data ' + str(filename))
|
print('EX: load_json no data ' + str(filename))
|
||||||
break
|
return json_object
|
||||||
|
|
||||||
# convert to json
|
# convert to json
|
||||||
try:
|
try:
|
||||||
json_object = json.loads(data)
|
json_object = json.loads(data)
|
||||||
break
|
except BaseException as exc:
|
||||||
except BaseException as exc:
|
print('EX: load_json exception ' + str(filename) + ' ' + str(exc))
|
||||||
print('EX: load_json exception ' +
|
|
||||||
str(tries) + ' ' + str(filename) + ' ' + str(exc))
|
|
||||||
if delay_sec > 0:
|
|
||||||
time.sleep(delay_sec)
|
|
||||||
tries += 1
|
|
||||||
return json_object
|
return json_object
|
||||||
|
|
||||||
|
|
||||||
|
@ -1729,7 +1722,7 @@ def get_display_name(base_dir: str, actor: str, person_cache: {}) -> str:
|
||||||
cached_actor_filename = \
|
cached_actor_filename = \
|
||||||
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
|
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
|
||||||
if os.path.isfile(cached_actor_filename):
|
if os.path.isfile(cached_actor_filename):
|
||||||
actor_json = load_json(cached_actor_filename, 1)
|
actor_json = load_json(cached_actor_filename)
|
||||||
if actor_json:
|
if actor_json:
|
||||||
if actor_json.get('name'):
|
if actor_json.get('name'):
|
||||||
name_found = actor_json['name']
|
name_found = actor_json['name']
|
||||||
|
@ -1805,7 +1798,7 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {},
|
||||||
cached_actor_filename = \
|
cached_actor_filename = \
|
||||||
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
|
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
|
||||||
if os.path.isfile(cached_actor_filename):
|
if os.path.isfile(cached_actor_filename):
|
||||||
actor_json = load_json(cached_actor_filename, 1)
|
actor_json = load_json(cached_actor_filename)
|
||||||
if not actor_json:
|
if not actor_json:
|
||||||
return default_gender
|
return default_gender
|
||||||
# is gender defined as a profile tag?
|
# is gender defined as a profile tag?
|
||||||
|
@ -2720,7 +2713,7 @@ def delete_post(base_dir: str, http_prefix: str,
|
||||||
manual: bool) -> None:
|
manual: bool) -> None:
|
||||||
"""Recursively deletes a post and its replies and attachments
|
"""Recursively deletes a post and its replies and attachments
|
||||||
"""
|
"""
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
# remove any replies
|
# remove any replies
|
||||||
_delete_post_remove_replies(base_dir, nickname, domain,
|
_delete_post_remove_replies(base_dir, nickname, domain,
|
||||||
|
@ -2991,7 +2984,7 @@ def is_public_post_from_url(base_dir: str, nickname: str, domain: str,
|
||||||
post_filename = locate_post(base_dir, nickname, domain, post_url)
|
post_filename = locate_post(base_dir, nickname, domain, post_url)
|
||||||
if not post_filename:
|
if not post_filename:
|
||||||
return False
|
return False
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename)
|
||||||
if not post_json_object:
|
if not post_json_object:
|
||||||
return False
|
return False
|
||||||
return is_public_post(post_json_object)
|
return is_public_post(post_json_object)
|
||||||
|
|
|
@ -2656,7 +2656,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
edits_filename = account_dir + box_name + '/' + edits_post_url
|
edits_filename = account_dir + box_name + '/' + edits_post_url
|
||||||
edits_str = ''
|
edits_str = ''
|
||||||
if os.path.isfile(edits_filename):
|
if os.path.isfile(edits_filename):
|
||||||
edits_json = load_json(edits_filename, 0, 1)
|
edits_json = load_json(edits_filename)
|
||||||
if edits_json:
|
if edits_json:
|
||||||
edits_str = create_edits_html(edits_json, post_json_object,
|
edits_str = create_edits_html(edits_json, post_json_object,
|
||||||
translate, timezone, system_language,
|
translate, timezone, system_language,
|
||||||
|
|
|
@ -181,7 +181,7 @@ def html_theme_designer(base_dir: str,
|
||||||
# set custom theme parameters
|
# set custom theme parameters
|
||||||
custom_variables_file = data_dir(base_dir) + '/theme.json'
|
custom_variables_file = data_dir(base_dir) + '/theme.json'
|
||||||
if os.path.isfile(custom_variables_file):
|
if os.path.isfile(custom_variables_file):
|
||||||
custom_theme_params = load_json(custom_variables_file, 0)
|
custom_theme_params = load_json(custom_variables_file)
|
||||||
if custom_theme_params:
|
if custom_theme_params:
|
||||||
for variable_name, value in custom_theme_params.items():
|
for variable_name, value in custom_theme_params.items():
|
||||||
theme_json[variable_name] = value
|
theme_json[variable_name] = value
|
||||||
|
|
Loading…
Reference in New Issue