Exception handling when reading from file

merge-requests/30/head
Bob Mottram 2024-07-13 21:27:19 +01:00
parent 21e2095696
commit a602cc61eb
10 changed files with 266 additions and 125 deletions

View File

@ -1212,15 +1212,19 @@ def html_profile(signing_priv_key_pem: str,
follow_requests_filename = \ follow_requests_filename = \
acct_dir(base_dir, nickname, domain) + '/followrequests.txt' acct_dir(base_dir, nickname, domain) + '/followrequests.txt'
if os.path.isfile(follow_requests_filename): if os.path.isfile(follow_requests_filename):
with open(follow_requests_filename, 'r', try:
encoding='utf-8') as foll_file: with open(follow_requests_filename, 'r',
for line in foll_file: encoding='utf-8') as foll_file:
if len(line) > 0: for line in foll_file:
follow_approvals = True if len(line) > 0:
followers_button = 'buttonhighlighted' follow_approvals = True
if selected == 'followers': followers_button = 'buttonhighlighted'
followers_button = 'buttonselectedhighlighted' if selected == 'followers':
break followers_button = 'buttonselectedhighlighted'
break
except OSError:
print('EX: html_profile unable to read ' +
follow_requests_filename)
if selected == 'followers': if selected == 'followers':
if follow_approvals: if follow_approvals:
curr_follower_domains = \ curr_follower_domains = \
@ -1323,8 +1327,11 @@ def html_profile(signing_priv_key_pem: str,
pinned_filename = account_dir + '/pinToProfile.txt' pinned_filename = account_dir + '/pinToProfile.txt'
pinned_content = None pinned_content = None
if os.path.isfile(pinned_filename): if os.path.isfile(pinned_filename):
with open(pinned_filename, 'r', encoding='utf-8') as pin_file: try:
pinned_content = pin_file.read() with open(pinned_filename, 'r', encoding='utf-8') as pin_file:
pinned_content = pin_file.read()
except OSError:
print('EX: html_profile unable to read ' + pinned_filename)
# shared items attached to the actor # shared items attached to the actor
# https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md # https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md
@ -2076,8 +2083,12 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
moderators = '' moderators = ''
moderators_file = data_dir(base_dir) + '/moderators.txt' moderators_file = data_dir(base_dir) + '/moderators.txt'
if os.path.isfile(moderators_file): if os.path.isfile(moderators_file):
with open(moderators_file, 'r', encoding='utf-8') as mod_file: try:
moderators = mod_file.read() with open(moderators_file, 'r', encoding='utf-8') as mod_file:
moderators = mod_file.read()
except OSError:
print('EX: _html_edit_profile_instance unable to read ' +
moderators_file)
subtitle = translate['A list of moderator nicknames. One per line.'] subtitle = translate['A list of moderator nicknames. One per line.']
role_assign_str += \ role_assign_str += \
edit_text_area('<b>' + translate['Moderators'] + '</b>', subtitle, edit_text_area('<b>' + translate['Moderators'] + '</b>', subtitle,
@ -2086,8 +2097,12 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
editors = '' editors = ''
editors_file = data_dir(base_dir) + '/editors.txt' editors_file = data_dir(base_dir) + '/editors.txt'
if os.path.isfile(editors_file): if os.path.isfile(editors_file):
with open(editors_file, 'r', encoding='utf-8') as edit_file: try:
editors = edit_file.read() with open(editors_file, 'r', encoding='utf-8') as edit_file:
editors = edit_file.read()
except OSError:
print('EX: _html_edit_profile_instance unable to read ' +
editors_file)
subtitle = translate['A list of editor nicknames. One per line.'] subtitle = translate['A list of editor nicknames. One per line.']
role_assign_str += \ role_assign_str += \
edit_text_area('<b>' + translate['Site Editors'] + '</b>', edit_text_area('<b>' + translate['Site Editors'] + '</b>',
@ -2097,8 +2112,12 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
counselors = '' counselors = ''
counselors_file = data_dir(base_dir) + '/counselors.txt' counselors_file = data_dir(base_dir) + '/counselors.txt'
if os.path.isfile(counselors_file): if os.path.isfile(counselors_file):
with open(counselors_file, 'r', encoding='utf-8') as co_file: try:
counselors = co_file.read() with open(counselors_file, 'r', encoding='utf-8') as co_file:
counselors = co_file.read()
except OSError:
print('EX: _html_edit_profile_instance unable to read ' +
counselors_file)
role_assign_str += \ role_assign_str += \
edit_text_area('<b>' + translate['Counselors'] + '</b>', None, edit_text_area('<b>' + translate['Counselors'] + '</b>', None,
'counselors', counselors, 200, '', False) 'counselors', counselors, 200, '', False)
@ -2107,8 +2126,12 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
artists = '' artists = ''
artists_file = data_dir(base_dir) + '/artists.txt' artists_file = data_dir(base_dir) + '/artists.txt'
if os.path.isfile(artists_file): if os.path.isfile(artists_file):
with open(artists_file, 'r', encoding='utf-8') as art_file: try:
artists = art_file.read() with open(artists_file, 'r', encoding='utf-8') as art_file:
artists = art_file.read()
except OSError:
print('EX: _html_edit_profile_instance unable to read ' +
artists_file)
role_assign_str += \ role_assign_str += \
edit_text_area('<b>' + translate['Artists'] + '</b>', None, edit_text_area('<b>' + translate['Artists'] + '</b>', None,
'artists', artists, 200, '', False) 'artists', artists, 200, '', False)
@ -2117,8 +2140,12 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
devops = '' devops = ''
devops_file = data_dir(base_dir) + '/devops.txt' devops_file = data_dir(base_dir) + '/devops.txt'
if os.path.isfile(devops_file): if os.path.isfile(devops_file):
with open(devops_file, 'r', encoding='utf-8') as edit_file: try:
devops = edit_file.read() with open(devops_file, 'r', encoding='utf-8') as edit_file:
devops = edit_file.read()
except OSError:
print('EX: _html_edit_profile_instance unable to read ' +
devops_file)
subtitle = translate['A list of devops nicknames. One per line.'] subtitle = translate['A list of devops nicknames. One per line.']
role_assign_str += \ role_assign_str += \
edit_text_area('<b>' + translate['Site DevOps'] + '</b>', edit_text_area('<b>' + translate['Site DevOps'] + '</b>',
@ -2238,8 +2265,13 @@ def _html_edit_profile_git_projects(base_dir: str, nickname: str, domain: str,
git_projects_filename = \ git_projects_filename = \
acct_dir(base_dir, nickname, domain) + '/gitprojects.txt' acct_dir(base_dir, nickname, domain) + '/gitprojects.txt'
if os.path.isfile(git_projects_filename): if os.path.isfile(git_projects_filename):
with open(git_projects_filename, 'r', encoding='utf-8') as git_file: try:
git_projects_str = git_file.read() with open(git_projects_filename, 'r',
encoding='utf-8') as git_file:
git_projects_str = git_file.read()
except OSError:
print('EX: _html_edit_profile_git_projects unable to read ' +
git_projects_filename)
edit_profile_form = begin_edit_section(translate['Git Projects']) edit_profile_form = begin_edit_section(translate['Git Projects'])
idx = 'List of project names that you wish to receive git patches for' idx = 'List of project names that you wish to receive git patches for'
@ -2284,36 +2316,57 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
filter_filename = \ filter_filename = \
acct_dir(base_dir, nickname, domain) + '/filters.txt' acct_dir(base_dir, nickname, domain) + '/filters.txt'
if os.path.isfile(filter_filename): if os.path.isfile(filter_filename):
with open(filter_filename, 'r', encoding='utf-8') as filterfile: try:
filter_str = filterfile.read() with open(filter_filename, 'r', encoding='utf-8') as filterfile:
filter_str = filterfile.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
filter_filename)
filter_bio_str = '' filter_bio_str = ''
filter_bio_filename = \ filter_bio_filename = \
acct_dir(base_dir, nickname, domain) + '/filters_bio.txt' acct_dir(base_dir, nickname, domain) + '/filters_bio.txt'
if os.path.isfile(filter_bio_filename): if os.path.isfile(filter_bio_filename):
with open(filter_bio_filename, 'r', encoding='utf-8') as filterfile: try:
filter_bio_str = filterfile.read() with open(filter_bio_filename, 'r',
encoding='utf-8') as fp_filter:
filter_bio_str = fp_filter.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
filter_bio_filename)
switch_str = '' switch_str = ''
switch_filename = \ switch_filename = \
acct_dir(base_dir, nickname, domain) + '/replacewords.txt' acct_dir(base_dir, nickname, domain) + '/replacewords.txt'
if os.path.isfile(switch_filename): if os.path.isfile(switch_filename):
with open(switch_filename, 'r', encoding='utf-8') as switchfile: try:
switch_str = switchfile.read() with open(switch_filename, 'r', encoding='utf-8') as switchfile:
switch_str = switchfile.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to save ' +
switch_filename)
auto_tags = '' auto_tags = ''
auto_tags_filename = \ auto_tags_filename = \
acct_dir(base_dir, nickname, domain) + '/autotags.txt' acct_dir(base_dir, nickname, domain) + '/autotags.txt'
if os.path.isfile(auto_tags_filename): if os.path.isfile(auto_tags_filename):
with open(auto_tags_filename, 'r', encoding='utf-8') as auto_file: try:
auto_tags = auto_file.read() with open(auto_tags_filename, 'r', encoding='utf-8') as auto_file:
auto_tags = auto_file.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
auto_tags_filename)
auto_cw = '' auto_cw = ''
auto_cw_filename = \ auto_cw_filename = \
acct_dir(base_dir, nickname, domain) + '/autocw.txt' acct_dir(base_dir, nickname, domain) + '/autocw.txt'
if os.path.isfile(auto_cw_filename): if os.path.isfile(auto_cw_filename):
with open(auto_cw_filename, 'r', encoding='utf-8') as cw_file: try:
auto_cw = cw_file.read() with open(auto_cw_filename, 'r', encoding='utf-8') as cw_file:
auto_cw = cw_file.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
auto_cw_filename)
blocked_str = get_account_blocks(base_dir, nickname, domain) blocked_str = get_account_blocks(base_dir, nickname, domain)
@ -2321,17 +2374,25 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
dm_allowed_instances_filename = \ dm_allowed_instances_filename = \
acct_dir(base_dir, nickname, domain) + '/dmAllowedInstances.txt' acct_dir(base_dir, nickname, domain) + '/dmAllowedInstances.txt'
if os.path.isfile(dm_allowed_instances_filename): if os.path.isfile(dm_allowed_instances_filename):
with open(dm_allowed_instances_filename, 'r', try:
encoding='utf-8') as dm_file: with open(dm_allowed_instances_filename, 'r',
dm_allowed_instances_str = dm_file.read() encoding='utf-8') as dm_file:
dm_allowed_instances_str = dm_file.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
dm_allowed_instances_filename)
allowed_instances_str = '' allowed_instances_str = ''
allowed_instances_filename = \ allowed_instances_filename = \
acct_dir(base_dir, nickname, domain) + '/allowedinstances.txt' acct_dir(base_dir, nickname, domain) + '/allowedinstances.txt'
if os.path.isfile(allowed_instances_filename): if os.path.isfile(allowed_instances_filename):
with open(allowed_instances_filename, 'r', try:
encoding='utf-8') as allow_file: with open(allowed_instances_filename, 'r',
allowed_instances_str = allow_file.read() encoding='utf-8') as allow_file:
allowed_instances_str = allow_file.read()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
allowed_instances_filename)
edit_profile_form = begin_edit_section(translate['Filtering and Blocking']) edit_profile_form = begin_edit_section(translate['Filtering and Blocking'])
@ -2351,16 +2412,24 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
city = '' city = ''
city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt' city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt'
if os.path.isfile(city_filename): if os.path.isfile(city_filename):
with open(city_filename, 'r', encoding='utf-8') as city_file: try:
city1 = city_file.read() with open(city_filename, 'r', encoding='utf-8') as city_file:
city = remove_eol(city1) city1 = city_file.read()
city = remove_eol(city1)
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
city_filename)
locations_filename = base_dir + '/custom_locations.txt' locations_filename = base_dir + '/custom_locations.txt'
if not os.path.isfile(locations_filename): if not os.path.isfile(locations_filename):
locations_filename = base_dir + '/locations.txt' locations_filename = base_dir + '/locations.txt'
cities = [] cities = []
with open(locations_filename, 'r', encoding='utf-8') as loc_file: try:
cities = loc_file.readlines() with open(locations_filename, 'r', encoding='utf-8') as loc_file:
cities.sort() cities = loc_file.readlines()
cities.sort()
except OSError:
print('EX: _html_edit_profile_filtering unable to read ' +
locations_filename)
edit_profile_form += ' <select id="cityDropdown" ' + \ edit_profile_form += ' <select id="cityDropdown" ' + \
'name="cityDropdown" class="theme">\n' 'name="cityDropdown" class="theme">\n'
city = city.lower() city = city.lower()

View File

@ -38,8 +38,11 @@ def get_pwa_theme_colors(css_filename: str) -> (str, str):
return pwa_theme_color, pwa_theme_background_color return pwa_theme_color, pwa_theme_background_color
css_str = '' css_str = ''
with open(css_filename, 'r', encoding='utf-8') as fp_css: try:
css_str = fp_css.read() with open(css_filename, 'r', encoding='utf-8') as fp_css:
css_str = fp_css.read()
except OSError:
print('EX: get_pwa_theme_colors unable to read ' + css_filename)
pwa_theme_color = \ pwa_theme_color = \
_get_variable_from_css(css_str, 'pwa-theme-color') _get_variable_from_css(css_str, 'pwa-theme-color')

View File

@ -884,8 +884,12 @@ def html_hashtag_search(nickname: str, domain: str, port: int,
nickname = None nickname = None
# read the index # read the index
with open(hashtag_index_file, 'r', encoding='utf-8') as fp_hash: lines = []
lines = fp_hash.readlines() try:
with open(hashtag_index_file, 'r', encoding='utf-8') as fp_hash:
lines = fp_hash.readlines()
except OSError:
print('EX: html_hashtag_search unable to read ' + hashtag_index_file)
# read the css # read the css
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'
@ -1308,8 +1312,11 @@ def hashtag_search_rss(nickname: str, domain: str, port: int,
# read the index # read the index
lines = [] lines = []
with open(hashtag_index_file, 'r', encoding='utf-8') as fp_hash: try:
lines = fp_hash.readlines() with open(hashtag_index_file, 'r', encoding='utf-8') as fp_hash:
lines = fp_hash.readlines()
except OSError:
print('EX: hashtag_search_rss unable to read ' + hashtag_index_file)
if not lines: if not lines:
return None return None
@ -1419,8 +1426,12 @@ def hashtag_search_json(nickname: str, domain: str, port: int,
# read the index # read the index
lines = [] lines = []
with open(hashtag_index_file, 'r', encoding='utf-8') as fp_hash: try:
lines = fp_hash.readlines() with open(hashtag_index_file, 'r', encoding='utf-8') as fp_hash:
lines = fp_hash.readlines()
except OSError:
print('EX: hashtag_search_json unable to read ' +
hashtag_index_file)
if not lines: if not lines:
return None return None

View File

@ -35,10 +35,14 @@ def html_specification(base_dir: str, http_prefix: str,
specification_text = 'ActivityPub Protocol Specification.' specification_text = 'ActivityPub Protocol Specification.'
if os.path.isfile(specification_filename): if os.path.isfile(specification_filename):
with open(specification_filename, 'r', try:
encoding='utf-8') as fp_specification: with open(specification_filename, 'r',
md_text = markdown_example_numbers(fp_specification.read()) encoding='utf-8') as fp_specification:
specification_text = markdown_to_html(md_text) md_text = markdown_example_numbers(fp_specification.read())
specification_text = markdown_to_html(md_text)
except OSError:
print('EX: html_specification unable to read ' +
specification_filename)
specification_form = '' specification_form = ''
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'

View File

@ -93,8 +93,13 @@ def _get_help_for_timeline(base_dir: str, box_name: str) -> str:
get_config_param(base_dir, 'instanceTitle') get_config_param(base_dir, 'instanceTitle')
if not instance_title: if not instance_title:
instance_title = 'Epicyon' instance_title = 'Epicyon'
with open(help_filename, 'r', encoding='utf-8') as help_file: help_text = ''
help_text = help_file.read() try:
with open(help_filename, 'r', encoding='utf-8') as help_file:
help_text = help_file.read()
except OSError:
print('EX: _get_help_for_timeline unable to read ' + help_filename)
if help_text:
if dangerous_markup(help_text, False, []): if dangerous_markup(help_text, False, []):
return '' return ''
help_text = help_text.replace('INSTANCE', instance_title) help_text = help_text.replace('INSTANCE', instance_title)
@ -532,11 +537,14 @@ def html_timeline(default_timeline: str,
if os.path.isfile(calendar_file): if os.path.isfile(calendar_file):
new_calendar_event = True new_calendar_event = True
calendar_image = 'calendar_notify.png' calendar_image = 'calendar_notify.png'
with open(calendar_file, 'r', encoding='utf-8') as calfile: try:
calendar_path = calfile.read().replace('##sent##', '') with open(calendar_file, 'r', encoding='utf-8') as calfile:
calendar_path = remove_eol(calendar_path) calendar_path = calfile.read().replace('##sent##', '')
if '/calendar' not in calendar_path: calendar_path = remove_eol(calendar_path)
calendar_path = '/calendar' if '/calendar' not in calendar_path:
calendar_path = '/calendar'
except OSError:
print('EX: html_timeline unable to read ' + calendar_file)
# should the DM button be highlighted? # should the DM button be highlighted?
new_dm = False new_dm = False
@ -693,21 +701,27 @@ def html_timeline(default_timeline: str,
follow_requests_filename = \ follow_requests_filename = \
acct_dir(base_dir, nickname, domain) + '/followrequests.txt' acct_dir(base_dir, nickname, domain) + '/followrequests.txt'
if os.path.isfile(follow_requests_filename): if os.path.isfile(follow_requests_filename):
with open(follow_requests_filename, 'r', try:
encoding='utf-8') as foll_file: with open(follow_requests_filename, 'r',
for line in foll_file: encoding='utf-8') as foll_file:
if len(line) > 0: for line in foll_file:
# show follow approvals icon if len(line) > 0:
follow_approvals = \ # show follow approvals icon
'<a href="' + users_path + \ follow_approvals = \
'/followers#buttonheader" ' + \ '<a href="' + users_path + \
'accesskey="' + access_keys['followButton'] + '">' + \ '/followers#buttonheader" ' + \
'<img loading="lazy" decoding="async" ' + \ 'accesskey="' + \
'class="timelineicon" alt="' + \ access_keys['followButton'] + '">' + \
translate['Approve follow requests'] + \ '<img loading="lazy" decoding="async" ' + \
'" title="' + translate['Approve follow requests'] + \ 'class="timelineicon" alt="' + \
'" src="/icons/person.png"/></a>\n' translate['Approve follow requests'] + \
break '" title="' + \
translate['Approve follow requests'] + \
'" src="/icons/person.png"/></a>\n'
break
except OSError:
print('EX: html_timeline unable to read ' +
follow_requests_filename)
_log_timeline_timing(enable_timing_log, timeline_start_time, box_name, '3') _log_timeline_timing(enable_timing_log, timeline_start_time, box_name, '3')

View File

@ -34,8 +34,12 @@ def html_terms_of_service(base_dir: str,
tos_text = 'Terms of Service go here.' tos_text = 'Terms of Service go here.'
if os.path.isfile(dir_str + '/tos.md'): if os.path.isfile(dir_str + '/tos.md'):
with open(dir_str + '/tos.md', 'r', encoding='utf-8') as file: try:
tos_text = markdown_to_html(file.read()) with open(dir_str + '/tos.md', 'r', encoding='utf-8') as file:
tos_text = markdown_to_html(file.read())
except OSError:
print('EX: html_terms_of_service unable to read ' +
dir_str + '/tos.md')
tos_form = '' tos_form = ''
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'

View File

@ -94,8 +94,13 @@ def get_broken_link_substitute() -> str:
def html_following_list(base_dir: str, following_filename: str) -> str: def html_following_list(base_dir: str, following_filename: str) -> str:
"""Returns a list of handles being followed """Returns a list of handles being followed
""" """
with open(following_filename, 'r', encoding='utf-8') as following_file: msg = ''
msg = following_file.read() try:
with open(following_filename, 'r', encoding='utf-8') as following_file:
msg = following_file.read()
except OSError:
print('EX: html_following_list unable to read ' + following_filename)
if msg:
following_list = msg.split('\n') following_list = msg.split('\n')
following_list.sort() following_list.sort()
if following_list: if following_list:
@ -122,8 +127,13 @@ def csv_following_list(following_filename: str,
base_dir: str, nickname: str, domain: str) -> str: base_dir: str, nickname: str, domain: str) -> str:
"""Returns a csv of handles being followed """Returns a csv of handles being followed
""" """
with open(following_filename, 'r', encoding='utf-8') as following_file: msg = ''
msg = following_file.read() try:
with open(following_filename, 'r', encoding='utf-8') as following_file:
msg = following_file.read()
except OSError:
print('EX: csv_following_list unable to read ' + following_filename)
if msg:
following_list = msg.split('\n') following_list = msg.split('\n')
following_list.sort() following_list.sort()
if following_list: if following_list:
@ -2208,27 +2218,35 @@ def html_following_data_list(base_dir: str, nickname: str,
list_str = '<datalist id="' + following_type + 'Handles">\n' list_str = '<datalist id="' + following_type + 'Handles">\n'
following_filename = \ following_filename = \
acct_dir(base_dir, nickname, domain) + '/' + following_type + '.txt' acct_dir(base_dir, nickname, domain) + '/' + following_type + '.txt'
msg = None msg = ''
if os.path.isfile(following_filename): if os.path.isfile(following_filename):
with open(following_filename, 'r', try:
encoding='utf-8') as following_file: with open(following_filename, 'r',
msg = following_file.read() encoding='utf-8') as following_file:
# add your own handle, so that you can send DMs msg = following_file.read()
# to yourself as reminders # add your own handle, so that you can send DMs
msg += nickname + '@' + domain_full + '\n' # to yourself as reminders
msg += nickname + '@' + domain_full + '\n'
except OSError:
print('EX: html_following_data_list unable to read ' +
following_filename)
if msg: if msg:
# include petnames # include petnames
petnames_filename = \ petnames_filename = \
acct_dir(base_dir, nickname, domain) + '/petnames.txt' acct_dir(base_dir, nickname, domain) + '/petnames.txt'
if use_petnames and os.path.isfile(petnames_filename): if use_petnames and os.path.isfile(petnames_filename):
following_list = [] following_list = []
with open(petnames_filename, 'r', try:
encoding='utf-8') as petnames_file: with open(petnames_filename, 'r',
pet_str = petnames_file.read() encoding='utf-8') as fp_petnames:
# extract each petname and append it pet_str = fp_petnames.read()
petnames_list = pet_str.split('\n') # extract each petname and append it
for pet in petnames_list: petnames_list = pet_str.split('\n')
following_list.append(pet.split(' ')[0]) for pet in petnames_list:
following_list.append(pet.split(' ')[0])
except OSError:
print('EX: html_following_data_list unable to read ' +
petnames_filename)
# add the following.txt entries # add the following.txt entries
following_list += msg.split('\n') following_list += msg.split('\n')
else: else:
@ -2256,27 +2274,35 @@ def html_following_dropdown(base_dir: str, nickname: str,
list_str = '<select name="searchtext">\n' list_str = '<select name="searchtext">\n'
following_filename = \ following_filename = \
acct_dir(base_dir, nickname, domain) + '/' + following_type + '.txt' acct_dir(base_dir, nickname, domain) + '/' + following_type + '.txt'
msg = None msg = ''
if os.path.isfile(following_filename): if os.path.isfile(following_filename):
with open(following_filename, 'r', try:
encoding='utf-8') as following_file: with open(following_filename, 'r',
msg = following_file.read() encoding='utf-8') as fp_following:
# add your own handle, so that you can send DMs msg = fp_following.read()
# to yourself as reminders # add your own handle, so that you can send DMs
msg += nickname + '@' + domain_full + '\n' # to yourself as reminders
msg += nickname + '@' + domain_full + '\n'
except OSError:
print('EX: html_following_dropdown unable to read ' +
following_filename)
if msg: if msg:
# include petnames # include petnames
petnames_filename = \ petnames_filename = \
acct_dir(base_dir, nickname, domain) + '/petnames.txt' acct_dir(base_dir, nickname, domain) + '/petnames.txt'
if use_petnames and os.path.isfile(petnames_filename): if use_petnames and os.path.isfile(petnames_filename):
following_list = [] following_list = []
with open(petnames_filename, 'r', try:
encoding='utf-8') as petnames_file: with open(petnames_filename, 'r',
pet_str = petnames_file.read() encoding='utf-8') as fp_petnames:
# extract each petname and append it pet_str = fp_petnames.read()
petnames_list = pet_str.split('\n') # extract each petname and append it
for pet in petnames_list: petnames_list = pet_str.split('\n')
following_list.append(pet.split(' ')[0]) for pet in petnames_list:
following_list.append(pet.split(' ')[0])
except OSError:
print('EX: html_following_dropdown unable to read ' +
petnames_filename)
# add the following.txt entries # add the following.txt entries
following_list += msg.split('\n') following_list += msg.split('\n')
else: else:

View File

@ -83,10 +83,13 @@ def html_welcome_screen(base_dir: str, nickname: str,
instance_title = 'Epicyon' instance_title = 'Epicyon'
if os.path.isfile(welcome_filename): if os.path.isfile(welcome_filename):
with open(welcome_filename, 'r', encoding='utf-8') as fp_wel: try:
welcome_text = fp_wel.read() with open(welcome_filename, 'r', encoding='utf-8') as fp_wel:
welcome_text = welcome_text.replace('INSTANCE', instance_title) welcome_text = fp_wel.read()
welcome_text = markdown_to_html(remove_html(welcome_text)) welcome_text = welcome_text.replace('INSTANCE', instance_title)
welcome_text = markdown_to_html(remove_html(welcome_text))
except OSError:
print('EX: html_welcome_screen unable to read ' + welcome_filename)
welcome_form = '' welcome_form = ''
css_filename = base_dir + '/epicyon-welcome.css' css_filename = base_dir + '/epicyon-welcome.css'

View File

@ -52,10 +52,13 @@ def html_welcome_final(base_dir: str, nickname: str,
instance_title = 'Epicyon' instance_title = 'Epicyon'
if os.path.isfile(final_filename): if os.path.isfile(final_filename):
with open(final_filename, 'r', encoding='utf-8') as final_file: try:
final_text = final_file.read() with open(final_filename, 'r', encoding='utf-8') as fp_final:
final_text = final_text.replace('INSTANCE', instance_title) final_text = fp_final.read()
final_text = markdown_to_html(remove_html(final_text)) final_text = final_text.replace('INSTANCE', instance_title)
final_text = markdown_to_html(remove_html(final_text))
except OSError:
print('EX: html_welcome_final unable to read ' + final_filename)
final_form = '' final_form = ''
css_filename = base_dir + '/epicyon-welcome.css' css_filename = base_dir + '/epicyon-welcome.css'

View File

@ -59,10 +59,14 @@ def html_welcome_profile(base_dir: str, nickname: str, domain: str,
instance_title = 'Epicyon' instance_title = 'Epicyon'
if os.path.isfile(profile_filename): if os.path.isfile(profile_filename):
with open(profile_filename, 'r', encoding='utf-8') as fp_pro: try:
profile_text = fp_pro.read() with open(profile_filename, 'r', encoding='utf-8') as fp_pro:
profile_text = profile_text.replace('INSTANCE', instance_title) profile_text = fp_pro.read()
profile_text = markdown_to_html(remove_html(profile_text)) profile_text = profile_text.replace('INSTANCE', instance_title)
profile_text = markdown_to_html(remove_html(profile_text))
except OSError:
print('EX: html_welcome_profile unable to read ' +
profile_filename)
profile_form = '' profile_form = ''
css_filename = base_dir + '/epicyon-welcome.css' css_filename = base_dir + '/epicyon-welcome.css'