mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with function
parent
970db19b72
commit
97bd529ab1
39
utils.py
39
utils.py
|
|
@ -1872,7 +1872,7 @@ def remove_moderation_post_from_index(base_dir: str, post_url: str,
|
||||||
debug: bool) -> None:
|
debug: bool) -> None:
|
||||||
"""Removes a url from the moderation index
|
"""Removes a url from the moderation index
|
||||||
"""
|
"""
|
||||||
moderation_index_file = data_dir(base_dir) + '/moderation.txt'
|
moderation_index_file: str = data_dir(base_dir) + '/moderation.txt'
|
||||||
remove_post_from_index(post_url, debug, moderation_index_file)
|
remove_post_from_index(post_url, debug, moderation_index_file)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1882,16 +1882,16 @@ def _is_reply_to_blog_post(base_dir: str, nickname: str, domain: str,
|
||||||
"""
|
"""
|
||||||
if not has_object_dict(post_json_object):
|
if not has_object_dict(post_json_object):
|
||||||
return False
|
return False
|
||||||
reply_id = get_reply_to(post_json_object['object'])
|
reply_id: str = get_reply_to(post_json_object['object'])
|
||||||
if not reply_id:
|
if not reply_id:
|
||||||
return False
|
return False
|
||||||
if not isinstance(reply_id, str):
|
if not isinstance(reply_id, str):
|
||||||
return False
|
return False
|
||||||
blogs_index_filename = \
|
blogs_index_filename: str = \
|
||||||
acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
|
acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
|
||||||
if not os.path.isfile(blogs_index_filename):
|
if not os.path.isfile(blogs_index_filename):
|
||||||
return False
|
return False
|
||||||
post_id = remove_id_ending(reply_id)
|
post_id: str = remove_id_ending(reply_id)
|
||||||
post_id = post_id.replace('/', '#')
|
post_id = post_id.replace('/', '#')
|
||||||
if text_in_file(post_id, blogs_index_filename):
|
if text_in_file(post_id, blogs_index_filename):
|
||||||
return True
|
return True
|
||||||
|
|
@ -1904,25 +1904,26 @@ def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
|
||||||
manual: bool) -> None:
|
manual: bool) -> None:
|
||||||
"""Removes replies when deleting a post
|
"""Removes replies when deleting a post
|
||||||
"""
|
"""
|
||||||
replies_filename = post_filename.replace('.json', '.replies')
|
replies_filename: str = post_filename.replace('.json', '.replies')
|
||||||
if not os.path.isfile(replies_filename):
|
if not os.path.isfile(replies_filename):
|
||||||
return
|
return
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: removing replies to ' + post_filename)
|
print('DEBUG: removing replies to ' + post_filename)
|
||||||
try:
|
replies_list: list[str] = \
|
||||||
with open(replies_filename, 'r', encoding='utf-8') as fp_replies:
|
load_list(replies_filename,
|
||||||
for reply_id in fp_replies:
|
'EX: _delete_post_remove_replies unable to read ' +
|
||||||
reply_file = locate_post(base_dir, nickname, domain, reply_id)
|
replies_filename)
|
||||||
if not reply_file:
|
for reply_id in replies_list:
|
||||||
continue
|
reply_id_str: str = reply_id.replace('\n', '').replace('\r', '')
|
||||||
if not os.path.isfile(reply_file):
|
reply_file: str = \
|
||||||
continue
|
locate_post(base_dir, nickname, domain, reply_id_str)
|
||||||
delete_post(base_dir, http_prefix,
|
if not reply_file:
|
||||||
nickname, domain, reply_file, debug,
|
continue
|
||||||
recent_posts_cache, manual)
|
if not os.path.isfile(reply_file):
|
||||||
except OSError:
|
continue
|
||||||
print('EX: _delete_post_remove_replies unable to read ' +
|
delete_post(base_dir, http_prefix,
|
||||||
replies_filename)
|
nickname, domain, reply_file, debug,
|
||||||
|
recent_posts_cache, manual)
|
||||||
# remove the replies file
|
# remove the replies file
|
||||||
try:
|
try:
|
||||||
os.remove(replies_filename)
|
os.remove(replies_filename)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue