mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with functions
parent
7e9d013dd5
commit
946c584b98
20
git.py
20
git.py
|
|
@ -17,6 +17,7 @@ from utils import get_attachment_property_value
|
||||||
from utils import remove_html
|
from utils import remove_html
|
||||||
from utils import get_attributed_to
|
from utils import get_attributed_to
|
||||||
from utils import string_contains
|
from utils import string_contains
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def _git_format_content(content: str) -> str:
|
def _git_format_content(content: str) -> str:
|
||||||
|
|
@ -213,17 +214,14 @@ def receive_git_patch(base_dir: str, nickname: str, domain: str,
|
||||||
patch_str = \
|
patch_str = \
|
||||||
_git_add_from_handle(patch_str,
|
_git_add_from_handle(patch_str,
|
||||||
'@' + from_nickname + '@' + from_domain)
|
'@' + from_nickname + '@' + from_domain)
|
||||||
try:
|
if save_string(patch_str, patch_filename,
|
||||||
with open(patch_filename, 'w+', encoding='utf-8') as fp_patch:
|
'EX: receive_git_patch ' + patch_filename + ' 1 [ex]'):
|
||||||
fp_patch.write(patch_str)
|
patch_notify_filename = \
|
||||||
patch_notify_filename = \
|
acct_dir(base_dir, nickname, domain) + '/.newPatchContent'
|
||||||
acct_dir(base_dir, nickname, domain) + '/.newPatchContent'
|
if save_string(patch_str, patch_notify_filename,
|
||||||
with open(patch_notify_filename, 'w+',
|
'EX: receive_git_patch ' +
|
||||||
encoding='utf-8') as fp_patch_notify:
|
patch_filename + ' 2 [ex]'):
|
||||||
fp_patch_notify.write(patch_str)
|
return True
|
||||||
return True
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: receive_git_patch ' + patch_filename + ' ' + str(ex))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
488
happening.py
488
happening.py
|
|
@ -36,6 +36,7 @@ from context import get_individual_post_context
|
||||||
from session import get_method
|
from session import get_method
|
||||||
from auth import create_basic_auth_header
|
from auth import create_basic_auth_header
|
||||||
from conversation import post_id_to_convthread_id
|
from conversation import post_id_to_convthread_id
|
||||||
|
from data import load_list
|
||||||
from data import load_string
|
from data import load_string
|
||||||
from data import save_string
|
from data import save_string
|
||||||
from data import append_string
|
from data import append_string
|
||||||
|
|
@ -298,100 +299,98 @@ def get_todays_events(base_dir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
calendar_post_ids: list[str] = []
|
calendar_post_ids: list[str] = []
|
||||||
recreate_events_file: bool = False
|
recreate_events_file: bool = False
|
||||||
try:
|
calendar_list: list[str] = \
|
||||||
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
|
load_list(calendar_filename,
|
||||||
for post_id in fp_events:
|
'EX: get_todays_events failed to read ' +
|
||||||
post_id = remove_eol(post_id)
|
calendar_filename + ' [ex]')
|
||||||
post_filename = \
|
if calendar_list is not None:
|
||||||
locate_post(base_dir, nickname, domain, post_id)
|
for post_id in calendar_list:
|
||||||
if not post_filename:
|
post_id = remove_eol(post_id)
|
||||||
recreate_events_file = True
|
post_filename = \
|
||||||
|
locate_post(base_dir, nickname, domain, post_id)
|
||||||
|
if not post_filename:
|
||||||
|
recreate_events_file = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
post_json_object = load_json(post_filename)
|
||||||
|
if not _is_happening_post(post_json_object):
|
||||||
|
continue
|
||||||
|
|
||||||
|
content_language = system_language
|
||||||
|
if post_json_object.get('object'):
|
||||||
|
content = None
|
||||||
|
if post_json_object['object'].get('contentMap'):
|
||||||
|
sys_lang = system_language
|
||||||
|
content_map = post_json_object['object']['contentMap']
|
||||||
|
if content_map.get(sys_lang):
|
||||||
|
content = content_map[sys_lang]
|
||||||
|
content_language = sys_lang
|
||||||
|
if not content:
|
||||||
|
if post_json_object['object'].get('content'):
|
||||||
|
content = post_json_object['object']['content']
|
||||||
|
if content:
|
||||||
|
if not _event_text_match(content, text_match):
|
||||||
|
continue
|
||||||
|
|
||||||
|
public_event = is_public_post(post_json_object)
|
||||||
|
|
||||||
|
post_event: list[dict] = []
|
||||||
|
day_of_month = None
|
||||||
|
for tag in post_json_object['object']['tag']:
|
||||||
|
if not _is_happening_event(tag):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
post_json_object = load_json(post_filename)
|
# this tag is an event or a place
|
||||||
if not _is_happening_post(post_json_object):
|
if tag['type'] != 'Event':
|
||||||
continue
|
# tag is a place
|
||||||
|
|
||||||
content_language = system_language
|
|
||||||
if post_json_object.get('object'):
|
|
||||||
content = None
|
|
||||||
if post_json_object['object'].get('contentMap'):
|
|
||||||
sys_lang = system_language
|
|
||||||
content_map = post_json_object['object']['contentMap']
|
|
||||||
if content_map.get(sys_lang):
|
|
||||||
content = content_map[sys_lang]
|
|
||||||
content_language = sys_lang
|
|
||||||
if not content:
|
|
||||||
if post_json_object['object'].get('content'):
|
|
||||||
content = post_json_object['object']['content']
|
|
||||||
if content:
|
|
||||||
if not _event_text_match(content, text_match):
|
|
||||||
continue
|
|
||||||
|
|
||||||
public_event = is_public_post(post_json_object)
|
|
||||||
|
|
||||||
post_event: list[dict] = []
|
|
||||||
day_of_month = None
|
|
||||||
for tag in post_json_object['object']['tag']:
|
|
||||||
if not _is_happening_event(tag):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# this tag is an event or a place
|
|
||||||
if tag['type'] != 'Event':
|
|
||||||
# tag is a place
|
|
||||||
post_event.append(tag)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# tag is an event
|
|
||||||
if not tag.get('startTime'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# is the tag for this day?
|
|
||||||
event_time = \
|
|
||||||
date_from_string_format(tag['startTime'],
|
|
||||||
["%Y-%m-%dT%H:%M:%S%z"])
|
|
||||||
event_year = int(event_time.strftime("%Y"))
|
|
||||||
event_month = int(event_time.strftime("%m"))
|
|
||||||
event_day = int(event_time.strftime("%d"))
|
|
||||||
if not (event_year == year and
|
|
||||||
event_month == month_number and
|
|
||||||
event_day == day_number):
|
|
||||||
continue
|
|
||||||
|
|
||||||
day_of_month = str(event_day)
|
|
||||||
if '#statuses#' in post_id:
|
|
||||||
# link to the id so that the event can be
|
|
||||||
# easily deleted
|
|
||||||
tag['post_id'] = post_id.split('#statuses#')[1]
|
|
||||||
tag['id'] = post_id.replace('#', '/')
|
|
||||||
tag['sender'] = post_id.split('#statuses#')[0]
|
|
||||||
tag['sender'] = tag['sender'].replace('#', '/')
|
|
||||||
tag['public'] = public_event
|
|
||||||
tag['language'] = content_language
|
|
||||||
post_event.append(tag)
|
post_event.append(tag)
|
||||||
|
|
||||||
if not (post_event and day_of_month):
|
|
||||||
continue
|
continue
|
||||||
calendar_post_ids.append(post_id)
|
|
||||||
if not events.get(day_of_month):
|
# tag is an event
|
||||||
events[day_of_month]: list[dict] = []
|
if not tag.get('startTime'):
|
||||||
events[day_of_month].append(post_event)
|
continue
|
||||||
events[day_of_month] = \
|
|
||||||
_sort_todays_events(events[day_of_month])
|
# is the tag for this day?
|
||||||
except OSError as exc:
|
event_time = \
|
||||||
print('EX: get_todays_events failed to read ' +
|
date_from_string_format(tag['startTime'],
|
||||||
calendar_filename + ' ' + str(exc))
|
["%Y-%m-%dT%H:%M:%S%z"])
|
||||||
|
event_year = int(event_time.strftime("%Y"))
|
||||||
|
event_month = int(event_time.strftime("%m"))
|
||||||
|
event_day = int(event_time.strftime("%d"))
|
||||||
|
if not (event_year == year and
|
||||||
|
event_month == month_number and
|
||||||
|
event_day == day_number):
|
||||||
|
continue
|
||||||
|
|
||||||
|
day_of_month = str(event_day)
|
||||||
|
if '#statuses#' in post_id:
|
||||||
|
# link to the id so that the event can be
|
||||||
|
# easily deleted
|
||||||
|
tag['post_id'] = post_id.split('#statuses#')[1]
|
||||||
|
tag['id'] = post_id.replace('#', '/')
|
||||||
|
tag['sender'] = post_id.split('#statuses#')[0]
|
||||||
|
tag['sender'] = tag['sender'].replace('#', '/')
|
||||||
|
tag['public'] = public_event
|
||||||
|
tag['language'] = content_language
|
||||||
|
post_event.append(tag)
|
||||||
|
|
||||||
|
if not (post_event and day_of_month):
|
||||||
|
continue
|
||||||
|
calendar_post_ids.append(post_id)
|
||||||
|
if not events.get(day_of_month):
|
||||||
|
events[day_of_month]: list[dict] = []
|
||||||
|
events[day_of_month].append(post_event)
|
||||||
|
events[day_of_month] = \
|
||||||
|
_sort_todays_events(events[day_of_month])
|
||||||
|
|
||||||
# if some posts have been deleted then regenerate the calendar file
|
# if some posts have been deleted then regenerate the calendar file
|
||||||
if recreate_events_file:
|
if recreate_events_file:
|
||||||
try:
|
text: str = ''
|
||||||
with open(calendar_filename, 'w+',
|
for post_id in calendar_post_ids:
|
||||||
encoding='utf-8') as fp_calendar:
|
text += post_id + '\n'
|
||||||
for post_id in calendar_post_ids:
|
save_string(text, calendar_filename,
|
||||||
fp_calendar.write(post_id + '\n')
|
'EX: unable to recreate events file 1 ' +
|
||||||
except OSError:
|
calendar_filename)
|
||||||
print('EX: unable to recreate events file 1 ' +
|
|
||||||
calendar_filename)
|
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
@ -625,41 +624,41 @@ def day_events_check(base_dir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
events_exist: bool = False
|
events_exist: bool = False
|
||||||
try:
|
calendar_list: list[str] = \
|
||||||
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
|
load_list(calendar_filename,
|
||||||
for post_id in fp_events:
|
'EX: day_events_check failed to read ' + calendar_filename)
|
||||||
post_id = remove_eol(post_id)
|
if calendar_list is not None:
|
||||||
post_filename = \
|
for post_id in calendar_list:
|
||||||
locate_post(base_dir, nickname, domain, post_id)
|
post_id = remove_eol(post_id)
|
||||||
if not post_filename:
|
post_filename = \
|
||||||
continue
|
locate_post(base_dir, nickname, domain, post_id)
|
||||||
|
if not post_filename:
|
||||||
|
continue
|
||||||
|
|
||||||
post_json_object = load_json(post_filename)
|
post_json_object = load_json(post_filename)
|
||||||
if not _is_happening_post(post_json_object):
|
if not _is_happening_post(post_json_object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for tag in post_json_object['object']['tag']:
|
for tag in post_json_object['object']['tag']:
|
||||||
if not _is_happening_event(tag):
|
if not _is_happening_event(tag):
|
||||||
continue
|
continue
|
||||||
# this tag is an event or a place
|
# this tag is an event or a place
|
||||||
if tag['type'] != 'Event':
|
if tag['type'] != 'Event':
|
||||||
continue
|
continue
|
||||||
# tag is an event
|
# tag is an event
|
||||||
if not tag.get('startTime'):
|
if not tag.get('startTime'):
|
||||||
continue
|
continue
|
||||||
event_time = \
|
event_time = \
|
||||||
date_from_string_format(tag['startTime'],
|
date_from_string_format(tag['startTime'],
|
||||||
["%Y-%m-%dT%H:%M:%S%z"])
|
["%Y-%m-%dT%H:%M:%S%z"])
|
||||||
if int(event_time.strftime("%d")) != day_number:
|
if int(event_time.strftime("%d")) != day_number:
|
||||||
continue
|
continue
|
||||||
if int(event_time.strftime("%m")) != month_number:
|
if int(event_time.strftime("%m")) != month_number:
|
||||||
continue
|
continue
|
||||||
if int(event_time.strftime("%Y")) != year:
|
if int(event_time.strftime("%Y")) != year:
|
||||||
continue
|
continue
|
||||||
events_exist = True
|
events_exist = True
|
||||||
break
|
break
|
||||||
except OSError:
|
|
||||||
print('EX: day_events_check failed to read ' + calendar_filename)
|
|
||||||
|
|
||||||
return events_exist
|
return events_exist
|
||||||
|
|
||||||
|
|
@ -685,61 +684,60 @@ def get_this_weeks_events(base_dir: str, nickname: str, domain: str) -> {}:
|
||||||
|
|
||||||
calendar_post_ids: list[str] = []
|
calendar_post_ids: list[str] = []
|
||||||
recreate_events_file: bool = False
|
recreate_events_file: bool = False
|
||||||
try:
|
calendar_list: list[str] = \
|
||||||
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
|
load_list(calendar_filename,
|
||||||
for post_id in fp_events:
|
'EX: get_this_weeks_events failed to read ' +
|
||||||
post_id = remove_eol(post_id)
|
calendar_filename)
|
||||||
post_filename = \
|
if calendar_list is not None:
|
||||||
locate_post(base_dir, nickname, domain, post_id)
|
for post_id in calendar_list:
|
||||||
if not post_filename:
|
post_id = remove_eol(post_id)
|
||||||
recreate_events_file = True
|
post_filename = \
|
||||||
|
locate_post(base_dir, nickname, domain, post_id)
|
||||||
|
if not post_filename:
|
||||||
|
recreate_events_file = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
post_json_object = load_json(post_filename)
|
||||||
|
if not _is_happening_post(post_json_object):
|
||||||
|
continue
|
||||||
|
|
||||||
|
post_event: list[dict] = []
|
||||||
|
week_day_index = None
|
||||||
|
for tag in post_json_object['object']['tag']:
|
||||||
|
if not _is_happening_event(tag):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
post_json_object = load_json(post_filename)
|
# this tag is an event or a place
|
||||||
if not _is_happening_post(post_json_object):
|
if tag['type'] != 'Event':
|
||||||
|
# tag is a place
|
||||||
|
post_event.append(tag)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
post_event: list[dict] = []
|
# tag is an event
|
||||||
week_day_index = None
|
if not tag.get('startTime'):
|
||||||
for tag in post_json_object['object']['tag']:
|
|
||||||
if not _is_happening_event(tag):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# this tag is an event or a place
|
|
||||||
if tag['type'] != 'Event':
|
|
||||||
# tag is a place
|
|
||||||
post_event.append(tag)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# tag is an event
|
|
||||||
if not tag.get('startTime'):
|
|
||||||
continue
|
|
||||||
event_time = \
|
|
||||||
date_from_string_format(tag['startTime'],
|
|
||||||
["%Y-%m-%dT%H:%M:%S%z"])
|
|
||||||
if now <= event_time <= end_of_week:
|
|
||||||
week_day_index = (event_time - now).days()
|
|
||||||
post_event.append(tag)
|
|
||||||
|
|
||||||
if not (post_event and week_day_index):
|
|
||||||
continue
|
continue
|
||||||
calendar_post_ids.append(post_id)
|
event_time = \
|
||||||
if not events.get(week_day_index):
|
date_from_string_format(tag['startTime'],
|
||||||
events[week_day_index]: list[dict] = []
|
["%Y-%m-%dT%H:%M:%S%z"])
|
||||||
events[week_day_index].append(post_event)
|
if now <= event_time <= end_of_week:
|
||||||
except OSError:
|
week_day_index = (event_time - now).days()
|
||||||
print('EX: get_this_weeks_events failed to read ' + calendar_filename)
|
post_event.append(tag)
|
||||||
|
|
||||||
|
if not (post_event and week_day_index):
|
||||||
|
continue
|
||||||
|
calendar_post_ids.append(post_id)
|
||||||
|
if not events.get(week_day_index):
|
||||||
|
events[week_day_index]: list[dict] = []
|
||||||
|
events[week_day_index].append(post_event)
|
||||||
|
|
||||||
# if some posts have been deleted then regenerate the calendar file
|
# if some posts have been deleted then regenerate the calendar file
|
||||||
if recreate_events_file:
|
if recreate_events_file:
|
||||||
try:
|
text: str = ''
|
||||||
with open(calendar_filename, 'w+',
|
for post_id in calendar_post_ids:
|
||||||
encoding='utf-8') as fp_calendar:
|
text += post_id + '\n'
|
||||||
for post_id in calendar_post_ids:
|
save_string(text, calendar_filename,
|
||||||
fp_calendar.write(post_id + '\n')
|
'EX: unable to recreate events file 2 ' +
|
||||||
except OSError:
|
calendar_filename)
|
||||||
print('EX: unable to recreate events file 2 ' +
|
|
||||||
calendar_filename)
|
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
@ -762,85 +760,84 @@ def get_calendar_events(base_dir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
calendar_post_ids: list[str] = []
|
calendar_post_ids: list[str] = []
|
||||||
recreate_events_file: bool = False
|
recreate_events_file: bool = False
|
||||||
try:
|
calendar_list: list[str] = \
|
||||||
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
|
load_list(calendar_filename,
|
||||||
for post_id in fp_events:
|
'EX: get_calendar_events failed to read ' +
|
||||||
post_id = remove_eol(post_id)
|
calendar_filename)
|
||||||
post_filename = \
|
if calendar_list is not None:
|
||||||
locate_post(base_dir, nickname, domain, post_id)
|
for post_id in calendar_list:
|
||||||
if not post_filename:
|
post_id = remove_eol(post_id)
|
||||||
recreate_events_file = True
|
post_filename = \
|
||||||
|
locate_post(base_dir, nickname, domain, post_id)
|
||||||
|
if not post_filename:
|
||||||
|
recreate_events_file = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
post_json_object = load_json(post_filename)
|
||||||
|
if not post_json_object:
|
||||||
|
continue
|
||||||
|
if not _is_happening_post(post_json_object):
|
||||||
|
continue
|
||||||
|
if only_show_reminders:
|
||||||
|
if not is_reminder(post_json_object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
post_json_object = load_json(post_filename)
|
if post_json_object.get('object'):
|
||||||
if not post_json_object:
|
if post_json_object['object'].get('content'):
|
||||||
|
content = post_json_object['object']['content']
|
||||||
|
if not _event_text_match(content, text_match):
|
||||||
|
continue
|
||||||
|
|
||||||
|
post_event: list[dict] = []
|
||||||
|
day_of_month = None
|
||||||
|
for tag in post_json_object['object']['tag']:
|
||||||
|
if not _is_happening_event(tag):
|
||||||
continue
|
continue
|
||||||
if not _is_happening_post(post_json_object):
|
|
||||||
continue
|
|
||||||
if only_show_reminders:
|
|
||||||
if not is_reminder(post_json_object):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if post_json_object.get('object'):
|
# this tag is an event or a place
|
||||||
if post_json_object['object'].get('content'):
|
if tag['type'] != 'Event':
|
||||||
content = post_json_object['object']['content']
|
# tag is a place
|
||||||
if not _event_text_match(content, text_match):
|
|
||||||
continue
|
|
||||||
|
|
||||||
post_event: list[dict] = []
|
|
||||||
day_of_month = None
|
|
||||||
for tag in post_json_object['object']['tag']:
|
|
||||||
if not _is_happening_event(tag):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# this tag is an event or a place
|
|
||||||
if tag['type'] != 'Event':
|
|
||||||
# tag is a place
|
|
||||||
post_event.append(tag)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# tag is an event
|
|
||||||
if not tag.get('startTime'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# is the tag for this month?
|
|
||||||
event_time = \
|
|
||||||
date_from_string_format(tag['startTime'],
|
|
||||||
["%Y-%m-%dT%H:%M:%S%z"])
|
|
||||||
event_year = int(event_time.strftime("%Y"))
|
|
||||||
event_month = int(event_time.strftime("%m"))
|
|
||||||
if not (event_year == year and
|
|
||||||
event_month == month_number):
|
|
||||||
continue
|
|
||||||
|
|
||||||
event_day = int(event_time.strftime("%d"))
|
|
||||||
day_of_month = str(event_day)
|
|
||||||
if '#statuses#' in post_id:
|
|
||||||
tag['post_id'] = post_id.split('#statuses#')[1]
|
|
||||||
tag['id'] = post_id.replace('#', '/')
|
|
||||||
tag['sender'] = post_id.split('#statuses#')[0]
|
|
||||||
tag['sender'] = tag['sender'].replace('#', '/')
|
|
||||||
post_event.append(tag)
|
post_event.append(tag)
|
||||||
|
|
||||||
if not (post_event and day_of_month):
|
|
||||||
continue
|
continue
|
||||||
calendar_post_ids.append(post_id)
|
|
||||||
if not events.get(day_of_month):
|
# tag is an event
|
||||||
events[day_of_month]: list[dict] = []
|
if not tag.get('startTime'):
|
||||||
events[day_of_month].append(post_event)
|
continue
|
||||||
except OSError:
|
|
||||||
print('EX: get_calendar_events failed to read ' + calendar_filename)
|
# is the tag for this month?
|
||||||
|
event_time = \
|
||||||
|
date_from_string_format(tag['startTime'],
|
||||||
|
["%Y-%m-%dT%H:%M:%S%z"])
|
||||||
|
event_year = int(event_time.strftime("%Y"))
|
||||||
|
event_month = int(event_time.strftime("%m"))
|
||||||
|
if not (event_year == year and
|
||||||
|
event_month == month_number):
|
||||||
|
continue
|
||||||
|
|
||||||
|
event_day = int(event_time.strftime("%d"))
|
||||||
|
day_of_month = str(event_day)
|
||||||
|
if '#statuses#' in post_id:
|
||||||
|
tag['post_id'] = post_id.split('#statuses#')[1]
|
||||||
|
tag['id'] = post_id.replace('#', '/')
|
||||||
|
tag['sender'] = post_id.split('#statuses#')[0]
|
||||||
|
tag['sender'] = tag['sender'].replace('#', '/')
|
||||||
|
post_event.append(tag)
|
||||||
|
|
||||||
|
if not (post_event and day_of_month):
|
||||||
|
continue
|
||||||
|
calendar_post_ids.append(post_id)
|
||||||
|
if not events.get(day_of_month):
|
||||||
|
events[day_of_month]: list[dict] = []
|
||||||
|
events[day_of_month].append(post_event)
|
||||||
|
|
||||||
# if some posts have been deleted then regenerate the calendar file
|
# if some posts have been deleted then regenerate the calendar file
|
||||||
if recreate_events_file:
|
if recreate_events_file:
|
||||||
try:
|
text: str = ''
|
||||||
with open(calendar_filename, 'w+',
|
for post_id in calendar_post_ids:
|
||||||
encoding='utf-8') as fp_calendar:
|
text += post_id + '\n'
|
||||||
for post_id in calendar_post_ids:
|
save_string(text, calendar_filename,
|
||||||
fp_calendar.write(post_id + '\n')
|
'EX: unable to recreate events file 3 ' +
|
||||||
except OSError:
|
calendar_filename)
|
||||||
print('EX: unable to recreate events file 3 ' +
|
|
||||||
calendar_filename)
|
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
@ -869,15 +866,14 @@ def remove_calendar_event(base_dir: str, nickname: str, domain: str,
|
||||||
return
|
return
|
||||||
lines = lines_str.split('\n')
|
lines = lines_str.split('\n')
|
||||||
print('Removing calendar event: ' + message_id)
|
print('Removing calendar event: ' + message_id)
|
||||||
try:
|
text: str = ''
|
||||||
with open(calendar_filename, 'w+', encoding='utf-8') as fp_cal:
|
for line in lines:
|
||||||
for line in lines:
|
if message_id in line:
|
||||||
if message_id in line:
|
continue
|
||||||
continue
|
text += line + '\n'
|
||||||
fp_cal.write(line + '\n')
|
save_string(text, calendar_filename,
|
||||||
except OSError:
|
'EX: unable to remove calendar event ' +
|
||||||
print('EX: unable to remove calendar event ' +
|
calendar_filename)
|
||||||
calendar_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def _dav_decode_token(token: str) -> (int, int, str):
|
def _dav_decode_token(token: str) -> (int, int, str):
|
||||||
|
|
|
||||||
21
keys.py
21
keys.py
|
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
||||||
__module_group__ = "ActivityPub"
|
__module_group__ = "ActivityPub"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from data import load_string
|
||||||
|
|
||||||
|
|
||||||
def _get_local_private_key(base_dir: str, nickname: str, domain: str) -> str:
|
def _get_local_private_key(base_dir: str, nickname: str, domain: str) -> str:
|
||||||
|
|
@ -19,11 +20,11 @@ def _get_local_private_key(base_dir: str, nickname: str, domain: str) -> str:
|
||||||
key_filename = base_dir + '/keys/private/' + handle.lower() + '.key'
|
key_filename = base_dir + '/keys/private/' + handle.lower() + '.key'
|
||||||
if not os.path.isfile(key_filename):
|
if not os.path.isfile(key_filename):
|
||||||
return None
|
return None
|
||||||
try:
|
text = load_string(key_filename,
|
||||||
with open(key_filename, 'r', encoding='utf-8') as fp_pem:
|
'EX: _get_local_private_key unable to read ' +
|
||||||
return fp_pem.read()
|
key_filename)
|
||||||
except OSError:
|
if text is not None:
|
||||||
print('EX: _get_local_private_key unable to read ' + key_filename)
|
return text
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,11 +37,11 @@ def _get_local_public_key(base_dir: str, nickname: str, domain: str) -> str:
|
||||||
key_filename = base_dir + '/keys/public/' + handle.lower() + '.key'
|
key_filename = base_dir + '/keys/public/' + handle.lower() + '.key'
|
||||||
if not os.path.isfile(key_filename):
|
if not os.path.isfile(key_filename):
|
||||||
return None
|
return None
|
||||||
try:
|
text = load_string(key_filename,
|
||||||
with open(key_filename, 'r', encoding='utf-8') as fp_pem:
|
'EX: _get_local_public_key unable to read ' +
|
||||||
return fp_pem.read()
|
key_filename)
|
||||||
except OSError:
|
if text is not None:
|
||||||
print('EX: _get_local_public_key unable to read ' + key_filename)
|
return text
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
24
languages.py
24
languages.py
|
|
@ -20,6 +20,8 @@ from utils import get_config_param
|
||||||
from utils import local_actor_url
|
from utils import local_actor_url
|
||||||
from utils import resembles_url
|
from utils import resembles_url
|
||||||
from cache import get_person_from_cache
|
from cache import get_person_from_cache
|
||||||
|
from data import load_string
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def get_actor_languages(actor_json: {}) -> str:
|
def get_actor_languages(actor_json: {}) -> str:
|
||||||
|
|
@ -354,13 +356,9 @@ def set_default_post_language(base_dir: str, nickname: str, domain: str,
|
||||||
"""
|
"""
|
||||||
default_post_language_filename = \
|
default_post_language_filename = \
|
||||||
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
|
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
|
||||||
try:
|
save_string(language, default_post_language_filename,
|
||||||
with open(default_post_language_filename, 'w+',
|
'EX: Unable to write default post language ' +
|
||||||
encoding='utf-8') as fp_lang:
|
default_post_language_filename)
|
||||||
fp_lang.write(language)
|
|
||||||
except OSError:
|
|
||||||
print('EX: Unable to write default post language ' +
|
|
||||||
default_post_language_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def load_default_post_languages(base_dir: str) -> {}:
|
def load_default_post_languages(base_dir: str) -> {}:
|
||||||
|
|
@ -379,13 +377,11 @@ def load_default_post_languages(base_dir: str) -> {}:
|
||||||
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
|
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
|
||||||
if not os.path.isfile(default_post_language_filename):
|
if not os.path.isfile(default_post_language_filename):
|
||||||
continue
|
continue
|
||||||
try:
|
text = load_string(default_post_language_filename,
|
||||||
with open(default_post_language_filename, 'r',
|
'EX: Unable to read default post language ' +
|
||||||
encoding='utf-8') as fp_lang:
|
default_post_language_filename)
|
||||||
result[nickname] = fp_lang.read()
|
if text:
|
||||||
except OSError:
|
result[nickname] = text
|
||||||
print('EX: Unable to read default post language ' +
|
|
||||||
default_post_language_filename)
|
|
||||||
break
|
break
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
273
manualapprove.py
273
manualapprove.py
|
|
@ -24,6 +24,10 @@ from utils import is_yggdrasil_address
|
||||||
from threads import thread_with_trace
|
from threads import thread_with_trace
|
||||||
from threads import begin_thread
|
from threads import begin_thread
|
||||||
from session import create_session
|
from session import create_session
|
||||||
|
from data import save_string
|
||||||
|
from data import load_string
|
||||||
|
from data import append_string
|
||||||
|
from data import load_list
|
||||||
|
|
||||||
|
|
||||||
def manual_deny_follow_request2(session, session_onion, session_i2p,
|
def manual_deny_follow_request2(session, session_onion, session_i2p,
|
||||||
|
|
@ -60,13 +64,9 @@ def manual_deny_follow_request2(session, session_onion, session_i2p,
|
||||||
remove_from_follow_requests(base_dir, nickname, domain, deny_handle, debug)
|
remove_from_follow_requests(base_dir, nickname, domain, deny_handle, debug)
|
||||||
|
|
||||||
# Store rejected follows
|
# Store rejected follows
|
||||||
try:
|
append_string(deny_handle + '\n', rejected_follows_filename,
|
||||||
with open(rejected_follows_filename, 'a+',
|
'EX: manual_deny_follow_request2 unable to append ' +
|
||||||
encoding='utf-8') as fp_rejects:
|
rejected_follows_filename)
|
||||||
fp_rejects.write(deny_handle + '\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: manual_deny_follow_request2 unable to append ' +
|
|
||||||
rejected_follows_filename)
|
|
||||||
|
|
||||||
deny_nickname = deny_handle.split('@')[0]
|
deny_nickname = deny_handle.split('@')[0]
|
||||||
deny_domain = remove_eol(deny_handle.split('@')[1])
|
deny_domain = remove_eol(deny_handle.split('@')[1])
|
||||||
|
|
@ -144,22 +144,14 @@ def _approve_follower_handle(account_dir: str, approve_handle: str) -> None:
|
||||||
approved_filename = account_dir + '/approved.txt'
|
approved_filename = account_dir + '/approved.txt'
|
||||||
if os.path.isfile(approved_filename):
|
if os.path.isfile(approved_filename):
|
||||||
if not text_in_file(approve_handle, approved_filename):
|
if not text_in_file(approve_handle, approved_filename):
|
||||||
try:
|
append_string(approve_handle + '\n', approved_filename,
|
||||||
with open(approved_filename, 'a+',
|
'EX: _approve_follower_handle unable to append ' +
|
||||||
encoding='utf-8') as fp_approved:
|
approved_filename)
|
||||||
fp_approved.write(approve_handle + '\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: _approve_follower_handle unable to append ' +
|
|
||||||
approved_filename)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
save_string(approve_handle + '\n', approved_filename,
|
||||||
with open(approved_filename, 'w+',
|
'EX: _approve_follower_handle unable to write ' +
|
||||||
encoding='utf-8') as fp_approved:
|
approved_filename)
|
||||||
fp_approved.write(approve_handle + '\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: _approve_follower_handle unable to write ' +
|
|
||||||
approved_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def manual_approve_follow_request(session, session_onion, session_i2p,
|
def manual_approve_follow_request(session, session_onion, session_i2p,
|
||||||
|
|
@ -194,12 +186,12 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
||||||
|
|
||||||
# is the handle in the requests file?
|
# is the handle in the requests file?
|
||||||
approve_follows_str: str = ''
|
approve_follows_str: str = ''
|
||||||
try:
|
approve_follows_str2: str = \
|
||||||
with open(approve_follows_filename, 'r', encoding='utf-8') as fp_foll:
|
load_string(approve_follows_filename,
|
||||||
approve_follows_str = fp_foll.read()
|
'EX: manual_approve_follow_request unable to read ' +
|
||||||
except OSError:
|
approve_follows_filename)
|
||||||
print('EX: manual_approve_follow_request unable to read ' +
|
if approve_follows_str2:
|
||||||
approve_follows_filename)
|
approve_follows_str = approve_follows_str2
|
||||||
exists: bool = False
|
exists: bool = False
|
||||||
approve_handle_full = approve_handle
|
approve_handle_full = approve_handle
|
||||||
if approve_handle in approve_follows_str:
|
if approve_handle in approve_follows_str:
|
||||||
|
|
@ -234,118 +226,118 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
||||||
'" ' + approve_follows_filename)
|
'" ' + approve_follows_filename)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
approve_follows_text: str = ''
|
||||||
with open(approve_follows_filename + '.new', 'w+',
|
update_approved_followers: bool = False
|
||||||
encoding='utf-8') as fp_approve_new:
|
follow_activity_filename = None
|
||||||
update_approved_followers: bool = False
|
approve_follows_list: list[str] = \
|
||||||
follow_activity_filename = None
|
load_list(approve_follows_filename,
|
||||||
with open(approve_follows_filename, 'r',
|
'EX: manual_approve_follow_request ' +
|
||||||
encoding='utf-8') as fp_approve:
|
'unable to write ' + approve_follows_filename +
|
||||||
for handle_of_follow_requester in fp_approve:
|
'.new [ex]')
|
||||||
# is this the approved follow?
|
if approve_follows_list is not None:
|
||||||
appr_handl = approve_handle_full
|
for handle_of_follow_requester in approve_follows_list:
|
||||||
if not handle_of_follow_requester.startswith(appr_handl):
|
# is this the approved follow?
|
||||||
# this isn't the approved follow so it will remain
|
appr_handl = approve_handle_full
|
||||||
# in the requests file
|
if not handle_of_follow_requester.startswith(appr_handl):
|
||||||
fp_approve_new.write(handle_of_follow_requester)
|
# this isn't the approved follow so it will remain
|
||||||
continue
|
# in the requests file
|
||||||
|
approve_follows_text += handle_of_follow_requester
|
||||||
|
continue
|
||||||
|
|
||||||
handle_of_follow_requester = \
|
handle_of_follow_requester = \
|
||||||
remove_eol(handle_of_follow_requester)
|
remove_eol(handle_of_follow_requester)
|
||||||
handle_of_follow_requester = \
|
handle_of_follow_requester = \
|
||||||
handle_of_follow_requester.replace('\r', '')
|
handle_of_follow_requester.replace('\r', '')
|
||||||
port2 = port
|
port2 = port
|
||||||
if ':' in handle_of_follow_requester:
|
if ':' in handle_of_follow_requester:
|
||||||
port2 = \
|
port2 = get_port_from_domain(handle_of_follow_requester)
|
||||||
get_port_from_domain(handle_of_follow_requester)
|
requests_dir = account_dir + '/requests'
|
||||||
requests_dir = account_dir + '/requests'
|
follow_activity_filename = \
|
||||||
follow_activity_filename = \
|
requests_dir + '/' + handle_of_follow_requester + '.follow'
|
||||||
requests_dir + '/' + \
|
if not os.path.isfile(follow_activity_filename):
|
||||||
handle_of_follow_requester + '.follow'
|
update_approved_followers = True
|
||||||
if not os.path.isfile(follow_activity_filename):
|
continue
|
||||||
update_approved_followers = True
|
follow_json = load_json(follow_activity_filename)
|
||||||
continue
|
if not follow_json:
|
||||||
follow_json = load_json(follow_activity_filename)
|
update_approved_followers = True
|
||||||
if not follow_json:
|
continue
|
||||||
update_approved_followers = True
|
approve_nickname = approve_handle.split('@')[0]
|
||||||
continue
|
approve_domain = approve_handle.split('@')[1]
|
||||||
approve_nickname = approve_handle.split('@')[0]
|
approve_domain = remove_eol(approve_domain)
|
||||||
approve_domain = approve_handle.split('@')[1]
|
approve_domain = approve_domain.replace('\r', '')
|
||||||
approve_domain = remove_eol(approve_domain)
|
approve_port = port2
|
||||||
approve_domain = approve_domain.replace('\r', '')
|
if ':' in approve_domain:
|
||||||
approve_port = port2
|
approve_port = get_port_from_domain(approve_domain)
|
||||||
if ':' in approve_domain:
|
approve_domain = remove_domain_port(approve_domain)
|
||||||
approve_port = get_port_from_domain(approve_domain)
|
|
||||||
approve_domain = remove_domain_port(approve_domain)
|
|
||||||
|
|
||||||
curr_domain = domain
|
curr_domain = domain
|
||||||
curr_port = port
|
curr_port = port
|
||||||
curr_session = session
|
curr_session = session
|
||||||
curr_http_prefix = http_prefix
|
curr_http_prefix = http_prefix
|
||||||
curr_proxy_type = proxy_type
|
curr_proxy_type = proxy_type
|
||||||
if onion_domain and \
|
if onion_domain and \
|
||||||
not curr_domain.endswith('.onion') and \
|
not curr_domain.endswith('.onion') and \
|
||||||
approve_domain.endswith('.onion'):
|
approve_domain.endswith('.onion'):
|
||||||
curr_domain = onion_domain
|
curr_domain = onion_domain
|
||||||
curr_port = 80
|
curr_port = 80
|
||||||
approve_port = 80
|
approve_port = 80
|
||||||
curr_session = session_onion
|
curr_session = session_onion
|
||||||
curr_http_prefix = 'http'
|
curr_http_prefix = 'http'
|
||||||
curr_proxy_type = 'tor'
|
curr_proxy_type = 'tor'
|
||||||
elif (i2p_domain and
|
elif (i2p_domain and
|
||||||
not curr_domain.endswith('.i2p') and
|
not curr_domain.endswith('.i2p') and
|
||||||
approve_domain.endswith('.i2p')):
|
approve_domain.endswith('.i2p')):
|
||||||
curr_domain = i2p_domain
|
curr_domain = i2p_domain
|
||||||
curr_port = 80
|
curr_port = 80
|
||||||
approve_port = 80
|
approve_port = 80
|
||||||
curr_session = session_i2p
|
curr_session = session_i2p
|
||||||
curr_http_prefix = 'http'
|
curr_http_prefix = 'http'
|
||||||
curr_proxy_type = 'i2p'
|
curr_proxy_type = 'i2p'
|
||||||
elif (yggdrasil_domain and
|
elif (yggdrasil_domain and
|
||||||
not is_yggdrasil_address(curr_domain) and
|
not is_yggdrasil_address(curr_domain) and
|
||||||
is_yggdrasil_address(approve_domain)):
|
is_yggdrasil_address(approve_domain)):
|
||||||
curr_domain = yggdrasil_domain
|
curr_domain = yggdrasil_domain
|
||||||
curr_port = 80
|
curr_port = 80
|
||||||
approve_port = 80
|
approve_port = 80
|
||||||
curr_session = session_yggdrasil
|
curr_session = session_yggdrasil
|
||||||
curr_http_prefix = 'http'
|
curr_http_prefix = 'http'
|
||||||
curr_proxy_type = 'yggdrasil'
|
curr_proxy_type = 'yggdrasil'
|
||||||
|
|
||||||
if not curr_session:
|
if not curr_session:
|
||||||
curr_session = create_session(curr_proxy_type)
|
curr_session = create_session(curr_proxy_type)
|
||||||
|
|
||||||
print('Manual follow accept: Sending Accept for ' +
|
print('Manual follow accept: Sending Accept for ' +
|
||||||
handle + ' follow request from ' +
|
handle + ' follow request from ' +
|
||||||
approve_nickname + '@' + approve_domain)
|
approve_nickname + '@' + approve_domain)
|
||||||
actor_url = get_actor_from_post(follow_json)
|
actor_url = get_actor_from_post(follow_json)
|
||||||
followed_account_accepts(curr_session, base_dir,
|
followed_account_accepts(curr_session, base_dir,
|
||||||
curr_http_prefix,
|
curr_http_prefix,
|
||||||
nickname,
|
nickname,
|
||||||
curr_domain, curr_port,
|
curr_domain, curr_port,
|
||||||
approve_nickname,
|
approve_nickname,
|
||||||
approve_domain,
|
approve_domain,
|
||||||
approve_port,
|
approve_port,
|
||||||
actor_url,
|
actor_url,
|
||||||
federation_list,
|
federation_list,
|
||||||
follow_json,
|
follow_json,
|
||||||
send_threads, post_log,
|
send_threads, post_log,
|
||||||
cached_webfingers,
|
cached_webfingers,
|
||||||
person_cache,
|
person_cache,
|
||||||
debug,
|
debug,
|
||||||
project_version, False,
|
project_version, False,
|
||||||
signing_priv_key_pem,
|
signing_priv_key_pem,
|
||||||
domain,
|
domain,
|
||||||
onion_domain,
|
onion_domain,
|
||||||
i2p_domain,
|
i2p_domain,
|
||||||
yggdrasil_domain,
|
yggdrasil_domain,
|
||||||
followers_sync_cache,
|
followers_sync_cache,
|
||||||
sites_unavailable,
|
sites_unavailable,
|
||||||
system_language,
|
system_language,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
update_approved_followers = True
|
update_approved_followers = True
|
||||||
except OSError as exc:
|
save_string(approve_follows_text, approve_follows_filename + '.new',
|
||||||
print('EX: manual_approve_follow_request unable to write ' +
|
'EX: manual_approve_follow_request unable to write ' +
|
||||||
approve_follows_filename + '.new ' + str(exc))
|
approve_follows_filename + '.new [ex]')
|
||||||
|
|
||||||
followers_filename = account_dir + '/followers.txt'
|
followers_filename = account_dir + '/followers.txt'
|
||||||
if update_approved_followers:
|
if update_approved_followers:
|
||||||
|
|
@ -370,13 +362,10 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
||||||
else:
|
else:
|
||||||
print('Manual follow accept: first follower accepted for ' +
|
print('Manual follow accept: first follower accepted for ' +
|
||||||
handle + ' is ' + approve_handle_full)
|
handle + ' is ' + approve_handle_full)
|
||||||
try:
|
save_string(approve_handle_full + '\n',
|
||||||
with open(followers_filename, 'w+',
|
followers_filename,
|
||||||
encoding='utf-8') as fp_followers:
|
'EX: manual_approve_follow_request unable to write ' +
|
||||||
fp_followers.write(approve_handle_full + '\n')
|
followers_filename)
|
||||||
except OSError:
|
|
||||||
print('EX: manual_approve_follow_request unable to write ' +
|
|
||||||
followers_filename)
|
|
||||||
|
|
||||||
# only update the follow requests file if the follow is confirmed to be
|
# only update the follow requests file if the follow is confirmed to be
|
||||||
# in followers.txt
|
# in followers.txt
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue