Replace file operations with function

main
bashrc 2026-04-28 22:45:01 +01:00
parent 92a33c4810
commit 2ba0064cc7
1 changed files with 25 additions and 23 deletions

View File

@ -826,18 +826,19 @@ def get_followers_of_person(base_dir: str,
continue continue
if not os.path.isfile(filename): if not os.path.isfile(filename):
continue continue
try: following_list: list[str] = \
with open(filename, 'r', encoding='utf-8') as fp_following: load_list(filename,
for following_handle in fp_following: 'EX: get_followers_of_person unable to read ' +
following_handle2 = remove_eol(following_handle) filename + ' [ex]')
if following_handle2 != handle: if following_list is None:
continue continue
if account not in followers: for following_handle in following_list:
followers.append(account) following_handle2 = remove_eol(following_handle)
break if following_handle2 != handle:
except OSError as exc: continue
print('EX: get_followers_of_person unable to read ' + if account not in followers:
filename + ' ' + str(exc)) followers.append(account)
break
break break
return followers return followers
@ -1913,17 +1914,18 @@ def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
load_list(replies_filename, load_list(replies_filename,
'EX: _delete_post_remove_replies unable to read ' + 'EX: _delete_post_remove_replies unable to read ' +
replies_filename) replies_filename)
for reply_id in replies_list: if replies_list is not None:
reply_id_str: str = reply_id.replace('\n', '').replace('\r', '') for reply_id in replies_list:
reply_file: str = \ reply_id_str: str = reply_id.replace('\n', '').replace('\r', '')
locate_post(base_dir, nickname, domain, reply_id_str) reply_file: str = \
if not reply_file: locate_post(base_dir, nickname, domain, reply_id_str)
continue if not reply_file:
if not os.path.isfile(reply_file): continue
continue if not os.path.isfile(reply_file):
delete_post(base_dir, http_prefix, continue
nickname, domain, reply_file, debug, delete_post(base_dir, http_prefix,
recent_posts_cache, manual) 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)