mirror of https://gitlab.com/bashrc2/epicyon
Also remove replies
parent
b2bd7950c9
commit
fb495b0b52
40
posts.py
40
posts.py
|
|
@ -5682,7 +5682,9 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
print('EX: archive_posts_for_person unable to write ' +
|
print('EX: archive_posts_for_person unable to write ' +
|
||||||
index_filename)
|
index_filename)
|
||||||
|
|
||||||
# remove any edits
|
# remove any edits or replies
|
||||||
|
for ext_name in ('edits', 'replies'):
|
||||||
|
ext = '.' + ext_name
|
||||||
posts_in_box = os.scandir(box_dir)
|
posts_in_box = os.scandir(box_dir)
|
||||||
edits_in_box_dict = {}
|
edits_in_box_dict = {}
|
||||||
edits_ctr = 0
|
edits_ctr = 0
|
||||||
|
|
@ -5690,25 +5692,28 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
edit_files_ctr = 0
|
edit_files_ctr = 0
|
||||||
for post_filename in posts_in_box:
|
for post_filename in posts_in_box:
|
||||||
post_filename = post_filename.name
|
post_filename = post_filename.name
|
||||||
if not post_filename.endswith('.edits'):
|
if not post_filename.endswith(ext):
|
||||||
continue
|
continue
|
||||||
original_post_filename = post_filename.replace('.edits', '.json')
|
original_post_filename = post_filename.replace(ext, '.json')
|
||||||
full_original_filename = os.path.join(box_dir, original_post_filename)
|
full_original_filename = \
|
||||||
|
os.path.join(box_dir, original_post_filename)
|
||||||
full_filename = os.path.join(box_dir, post_filename)
|
full_filename = os.path.join(box_dir, post_filename)
|
||||||
if not os.path.isfile(full_original_filename):
|
if not os.path.isfile(full_original_filename):
|
||||||
# if the original file doesn't exist (was remotely deleted by its
|
# if the original file doesn't exist (was remotely deleted by
|
||||||
# author) then remove the corresponding edits
|
# its author) then remove the corresponding edits
|
||||||
try:
|
try:
|
||||||
os.remove(full_filename)
|
os.remove(full_filename)
|
||||||
edits_removed_ctr += 1
|
edits_removed_ctr += 1
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to remove edits file ' + full_filename)
|
print('EX: unable to remove ' + ext_name + ' file ' +
|
||||||
|
full_filename)
|
||||||
continue
|
continue
|
||||||
edit_files_ctr += 1
|
edit_files_ctr += 1
|
||||||
if os.path.isfile(full_filename):
|
if os.path.isfile(full_filename):
|
||||||
content = ''
|
content = ''
|
||||||
try:
|
try:
|
||||||
with open(full_filename, 'r', encoding='utf-8') as fp_content:
|
with open(full_filename, 'r',
|
||||||
|
encoding='utf-8') as fp_content:
|
||||||
content = fp_content.read()
|
content = fp_content.read()
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to open content 2 ' + full_filename)
|
print('EX: unable to open content 2 ' + full_filename)
|
||||||
|
|
@ -5724,13 +5729,13 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
edits_ctr += 1
|
edits_ctr += 1
|
||||||
|
|
||||||
if edits_removed_ctr > 0:
|
if edits_removed_ctr > 0:
|
||||||
print(str(edits_removed_ctr) + ' edits removed from ' + boxname +
|
print(str(edits_removed_ctr) + ' ' + ext_name + ' removed from ' +
|
||||||
' for ' + nickname + '@' + domain)
|
boxname + ' for ' + nickname + '@' + domain)
|
||||||
|
|
||||||
no_of_edits = edits_ctr
|
no_of_edits = edits_ctr
|
||||||
if no_of_edits <= max_posts_in_box:
|
if no_of_edits <= max_posts_in_box:
|
||||||
print('Checked ' + str(no_of_edits) + ' ' + boxname +
|
print('Checked ' + str(no_of_edits) + ' ' + boxname +
|
||||||
' edits in ' + str(edit_files_ctr) +
|
' ' + ext_name + ' in ' + str(edit_files_ctr) +
|
||||||
' files for ' + nickname + '@' + domain)
|
' files for ' + nickname + '@' + domain)
|
||||||
else:
|
else:
|
||||||
# sort the list in ascending order of date
|
# sort the list in ascending order of date
|
||||||
|
|
@ -5749,22 +5754,23 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
remove_edits_ctr += 1
|
remove_edits_ctr += 1
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: ' +
|
print('EX: ' +
|
||||||
'archive_posts_for_person unable to archive edit ' +
|
'archive_posts_for_person unable to archive ' +
|
||||||
file_path + ' -> ' + archive_path)
|
ext_name + ' ' + file_path + ' -> ' +
|
||||||
|
archive_path)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.remove(edit_filename)
|
os.remove(edit_filename)
|
||||||
remove_edits_ctr += 1
|
remove_edits_ctr += 1
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: ' +
|
print('EX: ' +
|
||||||
'archive_posts_for_person unable to delete edit ' +
|
'archive_posts_for_person unable to delete ' +
|
||||||
edit_filename)
|
ext_name + ' ' + edit_filename)
|
||||||
if archive_dir:
|
if archive_dir:
|
||||||
print('Archived ' + str(remove_edits_ctr) + ' ' + boxname +
|
print('Archived ' + str(remove_edits_ctr) + ' ' + boxname +
|
||||||
' edits for ' + nickname + '@' + domain)
|
' ' + ext_name + ' for ' + nickname + '@' + domain)
|
||||||
else:
|
else:
|
||||||
print('Removed ' + str(remove_edits_ctr) + ' ' + boxname +
|
print('Removed ' + str(remove_edits_ctr) + ' ' + boxname +
|
||||||
' edits for ' + nickname + '@' + domain)
|
' ' + ext_name + ' for ' + nickname + '@' + domain)
|
||||||
|
|
||||||
posts_in_box_dict = {}
|
posts_in_box_dict = {}
|
||||||
posts_ctr = 0
|
posts_ctr = 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue