mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with function
parent
55b69c0a71
commit
970db19b72
18
utils.py
18
utils.py
|
|
@ -1841,7 +1841,7 @@ def remove_post_from_index(post_url: str, debug: bool,
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile(index_file):
|
if not os.path.isfile(index_file):
|
||||||
return
|
return
|
||||||
post_id: str = remove_id_ending(post_url)
|
post_id: str = remove_id_ending(post_url).strip("\n").strip("\r")
|
||||||
if not text_in_file(post_id, index_file):
|
if not text_in_file(post_id, index_file):
|
||||||
return
|
return
|
||||||
lines: list[str] = \
|
lines: list[str] = \
|
||||||
|
|
@ -1851,19 +1851,21 @@ def remove_post_from_index(post_url: str, debug: bool,
|
||||||
|
|
||||||
if not lines:
|
if not lines:
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
with open(index_file, 'w+', encoding='utf-8') as fp_mod2:
|
new_index: str = ''
|
||||||
|
removed: bool = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip("\n").strip("\r") != post_id:
|
if line.strip("\n").strip("\r") != post_id:
|
||||||
fp_mod2.write(line)
|
new_index += line
|
||||||
continue
|
continue
|
||||||
|
removed = True
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: removed ' + post_id +
|
print('DEBUG: removed ' + post_id +
|
||||||
' from index ' + index_file)
|
' from index ' + index_file)
|
||||||
except OSError as exc:
|
if removed:
|
||||||
print('EX: ' +
|
save_string(new_index, index_file,
|
||||||
'remove_post_from_index unable to write ' +
|
'EX: remove_post_from_index unable to write ' +
|
||||||
index_file + ' ' + str(exc))
|
index_file + ' [ex]')
|
||||||
|
|
||||||
|
|
||||||
def remove_moderation_post_from_index(base_dir: str, post_url: str,
|
def remove_moderation_post_from_index(base_dir: str, post_url: str,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue