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 session import create_session
|
||||||
from threads import begin_thread
|
from threads import begin_thread
|
||||||
from siteactive import save_unavailable_sites
|
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,
|
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]
|
nickname = handle.split('@')[0]
|
||||||
shared_items_federated_domains = httpd.shared_items_federated_domains
|
shared_items_federated_domains = httpd.shared_items_federated_domains
|
||||||
shared_item_federation_tokens = httpd.shared_item_federation_tokens
|
shared_item_federation_tokens = httpd.shared_item_federation_tokens
|
||||||
try:
|
scheduled_list = load_list(schedule_index_filename,
|
||||||
with open(schedule_index_filename, 'r', encoding='utf-8') as fp_sched:
|
'EX: _update_post_schedule unable to read ' +
|
||||||
for line in fp_sched:
|
schedule_index_filename + ' [ex]')
|
||||||
|
if scheduled_list is not None:
|
||||||
|
for line in scheduled_list:
|
||||||
if ' ' not in line:
|
if ' ' not in line:
|
||||||
continue
|
continue
|
||||||
date_str = line.split(' ')[0]
|
date_str = line.split(' ')[0]
|
||||||
|
|
@ -190,20 +194,15 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
|
||||||
index_lines.remove(line)
|
index_lines.remove(line)
|
||||||
if len(index_lines) > max_scheduled_posts:
|
if len(index_lines) > max_scheduled_posts:
|
||||||
delete_schedule_post = True
|
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
|
# write the new schedule index file
|
||||||
schedule_index_file = \
|
schedule_index_file = \
|
||||||
acct_handle_dir(base_dir, handle) + '/schedule.index'
|
acct_handle_dir(base_dir, handle) + '/schedule.index'
|
||||||
try:
|
text = ''
|
||||||
with open(schedule_index_file, 'w+',
|
|
||||||
encoding='utf-8') as fp_schedule:
|
|
||||||
for line in index_lines:
|
for line in index_lines:
|
||||||
fp_schedule.write(line)
|
text += line
|
||||||
except OSError:
|
save_string(text, schedule_index_file,
|
||||||
print('EX: _update_post_schedule unable to write ' +
|
'EX: _update_post_schedule unable to write ' +
|
||||||
schedule_index_file)
|
schedule_index_file)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue