mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with function
parent
27ce1a8772
commit
f52a3e7ace
23
schedule.py
23
schedule.py
|
|
@ -24,6 +24,8 @@ from outbox import post_message_to_outbox
|
|||
from session import create_session
|
||||
from threads import begin_thread
|
||||
from siteactive import save_unavailable_sites
|
||||
from data import save_string
|
||||
from data import load_list
|
||||
|
||||
|
||||
def _update_post_schedule(base_dir: str, handle: str, httpd,
|
||||
|
|
@ -46,9 +48,11 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
|
|||
nickname = handle.split('@')[0]
|
||||
shared_items_federated_domains = httpd.shared_items_federated_domains
|
||||
shared_item_federation_tokens = httpd.shared_item_federation_tokens
|
||||
try:
|
||||
with open(schedule_index_filename, 'r', encoding='utf-8') as fp_sched:
|
||||
for line in fp_sched:
|
||||
scheduled_list = load_list(schedule_index_filename,
|
||||
'EX: _update_post_schedule unable to read ' +
|
||||
schedule_index_filename + ' [ex]')
|
||||
if scheduled_list is not None:
|
||||
for line in scheduled_list:
|
||||
if ' ' not in line:
|
||||
continue
|
||||
date_str = line.split(' ')[0]
|
||||
|
|
@ -190,20 +194,15 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
|
|||
index_lines.remove(line)
|
||||
if len(index_lines) > max_scheduled_posts:
|
||||
delete_schedule_post = True
|
||||
except OSError as exc:
|
||||
print('EX: _update_post_schedule unable to read ' +
|
||||
schedule_index_filename + ' ' + str(exc))
|
||||
|
||||
# write the new schedule index file
|
||||
schedule_index_file = \
|
||||
acct_handle_dir(base_dir, handle) + '/schedule.index'
|
||||
try:
|
||||
with open(schedule_index_file, 'w+',
|
||||
encoding='utf-8') as fp_schedule:
|
||||
text = ''
|
||||
for line in index_lines:
|
||||
fp_schedule.write(line)
|
||||
except OSError:
|
||||
print('EX: _update_post_schedule unable to write ' +
|
||||
text += line
|
||||
save_string(text, schedule_index_file,
|
||||
'EX: _update_post_schedule unable to write ' +
|
||||
schedule_index_file)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue