mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with functions
parent
9ae07571a7
commit
583a1ae83f
|
|
@ -21,6 +21,8 @@ from utils import resembles_url
|
||||||
from keys import get_instance_actor_key
|
from keys import get_instance_actor_key
|
||||||
from session import get_json
|
from session import get_json
|
||||||
from session import get_json_valid
|
from session import get_json_valid
|
||||||
|
from data import save_string
|
||||||
|
from data import append_string
|
||||||
|
|
||||||
|
|
||||||
def _get_conversation_filename(base_dir: str, nickname: str, domain: str,
|
def _get_conversation_filename(base_dir: str, nickname: str, domain: str,
|
||||||
|
|
@ -63,23 +65,17 @@ def update_conversation(base_dir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
post_id = remove_id_ending(post_json_object['object']['id'])
|
post_id = remove_id_ending(post_json_object['object']['id'])
|
||||||
if not os.path.isfile(conversation_filename):
|
if not os.path.isfile(conversation_filename):
|
||||||
try:
|
if save_string(post_id + '\n', conversation_filename,
|
||||||
with open(conversation_filename, 'w+',
|
'EX: update_conversation ' +
|
||||||
encoding='utf-8') as fp_conv:
|
'unable to write to ' +
|
||||||
fp_conv.write(post_id + '\n')
|
conversation_filename):
|
||||||
return True
|
return True
|
||||||
except OSError:
|
|
||||||
print('EX: update_conversation ' +
|
|
||||||
'unable to write to ' + conversation_filename)
|
|
||||||
elif not text_in_file(post_id + '\n', conversation_filename):
|
elif not text_in_file(post_id + '\n', conversation_filename):
|
||||||
try:
|
if append_string(post_id + '\n', conversation_filename,
|
||||||
with open(conversation_filename, 'a+',
|
'EX: update_conversation 2 ' +
|
||||||
encoding='utf-8') as fp_conv:
|
'unable to write to ' +
|
||||||
fp_conv.write(post_id + '\n')
|
conversation_filename):
|
||||||
return True
|
return True
|
||||||
except OSError:
|
|
||||||
print('EX: update_conversation 2 ' +
|
|
||||||
'unable to write to ' + conversation_filename)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -97,12 +93,8 @@ def mute_conversation(base_dir: str, nickname: str, domain: str,
|
||||||
return
|
return
|
||||||
if os.path.isfile(conversation_filename + '.muted'):
|
if os.path.isfile(conversation_filename + '.muted'):
|
||||||
return
|
return
|
||||||
try:
|
save_string('\n', conversation_filename + '.muted',
|
||||||
with open(conversation_filename + '.muted', 'w+',
|
'EX: unable to write mute ' + conversation_filename)
|
||||||
encoding='utf-8') as fp_conv:
|
|
||||||
fp_conv.write('\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to write mute ' + conversation_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def unmute_conversation(base_dir: str, nickname: str, domain: str,
|
def unmute_conversation(base_dir: str, nickname: str, domain: str,
|
||||||
|
|
|
||||||
21
crawlers.py
21
crawlers.py
|
|
@ -19,6 +19,8 @@ from blocking import get_bsky_domains_list
|
||||||
from blocking import get_nostr_domains_list
|
from blocking import get_nostr_domains_list
|
||||||
from blocking import update_blocked_cache
|
from blocking import update_blocked_cache
|
||||||
from blocking import is_blocked_domain
|
from blocking import is_blocked_domain
|
||||||
|
from data import load_string
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
default_user_agent_blocks = [
|
default_user_agent_blocks = [
|
||||||
'fedilist', 'ncsc scan', 'fedifetcher'
|
'fedilist', 'ncsc scan', 'fedifetcher'
|
||||||
|
|
@ -64,13 +66,9 @@ def load_known_web_bots(base_dir: str) -> []:
|
||||||
known_bots_filename = data_dir(base_dir) + '/knownBots.txt'
|
known_bots_filename = data_dir(base_dir) + '/knownBots.txt'
|
||||||
if not os.path.isfile(known_bots_filename):
|
if not os.path.isfile(known_bots_filename):
|
||||||
return []
|
return []
|
||||||
crawlers_str = None
|
crawlers_str = load_string(known_bots_filename,
|
||||||
try:
|
'EX: unable to load web bots from ' +
|
||||||
with open(known_bots_filename, 'r', encoding='utf-8') as fp_crawlers:
|
known_bots_filename)
|
||||||
crawlers_str = fp_crawlers.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to load web bots from ' +
|
|
||||||
known_bots_filename)
|
|
||||||
if not crawlers_str:
|
if not crawlers_str:
|
||||||
return []
|
return []
|
||||||
known_bots: list[str] = []
|
known_bots: list[str] = []
|
||||||
|
|
@ -93,12 +91,9 @@ def _save_known_web_bots(base_dir: str, known_bots: []) -> bool:
|
||||||
known_bots_str: str = ''
|
known_bots_str: str = ''
|
||||||
for crawler in known_bots:
|
for crawler in known_bots:
|
||||||
known_bots_str += crawler.strip() + '\n'
|
known_bots_str += crawler.strip() + '\n'
|
||||||
try:
|
if not save_string(known_bots_str, known_bots_filename,
|
||||||
with open(known_bots_filename, 'w+', encoding='utf-8') as fp_crawlers:
|
"EX: unable to save known web bots to " +
|
||||||
fp_crawlers.write(known_bots_str)
|
known_bots_filename):
|
||||||
except OSError:
|
|
||||||
print("EX: unable to save known web bots to " +
|
|
||||||
known_bots_filename)
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
22
daemon.py
22
daemon.py
|
|
@ -105,6 +105,7 @@ from daemon_utils import has_accept
|
||||||
from daemon_utils import is_authorized
|
from daemon_utils import is_authorized
|
||||||
from poison import load_dictionary
|
from poison import load_dictionary
|
||||||
from poison import load_2grams
|
from poison import load_2grams
|
||||||
|
from data import load_string
|
||||||
|
|
||||||
|
|
||||||
class PubServer(BaseHTTPRequestHandler):
|
class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
@ -583,14 +584,9 @@ def load_tokens(base_dir: str, tokens_dict: {}, tokens_lookup: {}) -> None:
|
||||||
if not os.path.isfile(token_filename):
|
if not os.path.isfile(token_filename):
|
||||||
continue
|
continue
|
||||||
nickname = handle.split('@')[0]
|
nickname = handle.split('@')[0]
|
||||||
token = None
|
token = load_string(token_filename,
|
||||||
try:
|
'WARN: Unable to read token for ' +
|
||||||
with open(token_filename, 'r',
|
nickname + ' [ex]')
|
||||||
encoding='utf-8') as fp_tok:
|
|
||||||
token = fp_tok.read()
|
|
||||||
except OSError as ex:
|
|
||||||
print('WARN: Unable to read token for ' +
|
|
||||||
nickname + ' ' + str(ex))
|
|
||||||
if not token:
|
if not token:
|
||||||
continue
|
continue
|
||||||
tokens_dict[nickname] = token
|
tokens_dict[nickname] = token
|
||||||
|
|
@ -753,13 +749,9 @@ def run_daemon(accounts_data_dir: str,
|
||||||
robots_txt_filename = data_dir(base_dir) + '/robots.txt'
|
robots_txt_filename = data_dir(base_dir) + '/robots.txt'
|
||||||
httpd.robots_txt = None
|
httpd.robots_txt = None
|
||||||
if os.path.isfile(robots_txt_filename):
|
if os.path.isfile(robots_txt_filename):
|
||||||
new_robots_txt = ''
|
new_robots_txt = \
|
||||||
try:
|
load_string(robots_txt_filename,
|
||||||
with open(robots_txt_filename, 'r',
|
'EX: error reading 1 ' + robots_txt_filename)
|
||||||
encoding='utf-8') as fp_robots:
|
|
||||||
new_robots_txt = fp_robots.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: error reading 1 ' + robots_txt_filename)
|
|
||||||
if new_robots_txt:
|
if new_robots_txt:
|
||||||
httpd.robots_txt = new_robots_txt
|
httpd.robots_txt = new_robots_txt
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,7 @@ from daemon_get_links import edit_links2
|
||||||
from daemon_get_login import redirect_to_login_screen
|
from daemon_get_login import redirect_to_login_screen
|
||||||
from daemon_get_login import show_login_screen
|
from daemon_get_login import show_login_screen
|
||||||
from poison import html_poisoned
|
from poison import html_poisoned
|
||||||
|
from data import load_string
|
||||||
|
|
||||||
# Blogs can be longer, so don't show many per page
|
# Blogs can be longer, so don't show many per page
|
||||||
MAX_POSTS_IN_BLOGS_FEED = 4
|
MAX_POSTS_IN_BLOGS_FEED = 4
|
||||||
|
|
@ -6255,12 +6256,8 @@ def daemon_http_get(self) -> None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
content = None
|
content = load_string(filename,
|
||||||
try:
|
'EX: unable to read file ' + filename)
|
||||||
with open(filename, 'r', encoding='utf-8') as fp_rfile:
|
|
||||||
content = fp_rfile.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to read file ' + filename)
|
|
||||||
if content:
|
if content:
|
||||||
try:
|
try:
|
||||||
content_json = json.loads(content)
|
content_json = json.loads(content)
|
||||||
|
|
@ -6500,13 +6497,10 @@ def _get_ontology(self, calling_domain: str,
|
||||||
if ontology_str.endswith('.json'):
|
if ontology_str.endswith('.json'):
|
||||||
ontology_file_type = 'application/ld+json'
|
ontology_file_type = 'application/ld+json'
|
||||||
if os.path.isfile(ontology_filename):
|
if os.path.isfile(ontology_filename):
|
||||||
ontology_file = None
|
ontology_file = \
|
||||||
try:
|
load_string(ontology_filename,
|
||||||
with open(ontology_filename, 'r',
|
'EX: unable to read ontology ' +
|
||||||
encoding='utf-8') as fp_ont:
|
ontology_filename)
|
||||||
ontology_file = fp_ont.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to read ontology ' + ontology_filename)
|
|
||||||
if ontology_file:
|
if ontology_file:
|
||||||
ontology_file = \
|
ontology_file = \
|
||||||
ontology_file.replace('static.datafoodconsortium.org',
|
ontology_file.replace('static.datafoodconsortium.org',
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ from daemon_utils import etag_exists
|
||||||
from fitnessFunctions import fitness_performance
|
from fitnessFunctions import fitness_performance
|
||||||
from person import save_person_qrcode
|
from person import save_person_qrcode
|
||||||
from lxmf import save_lxmf_qrcode
|
from lxmf import save_lxmf_qrcode
|
||||||
|
from data import load_string
|
||||||
|
|
||||||
|
|
||||||
def show_avatar_or_banner(self, referer_domain: str, path: str,
|
def show_avatar_or_banner(self, referer_domain: str, path: str,
|
||||||
|
|
@ -442,16 +443,12 @@ def show_media(self, path: str, base_dir: str,
|
||||||
last_modified_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
last_modified_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||||
|
|
||||||
if media_filename.endswith('.vtt'):
|
if media_filename.endswith('.vtt'):
|
||||||
media_transcript = None
|
media_transcript = \
|
||||||
try:
|
load_string(media_filename,
|
||||||
with open(media_filename, 'r',
|
'EX: unable to read media binary ' +
|
||||||
encoding='utf-8') as fp_vtt:
|
media_filename)
|
||||||
media_transcript = fp_vtt.read()
|
|
||||||
media_file_type = 'text/vtt; charset=utf-8'
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to read media binary ' +
|
|
||||||
media_filename)
|
|
||||||
if media_transcript:
|
if media_transcript:
|
||||||
|
media_file_type = 'text/vtt; charset=utf-8'
|
||||||
media_transcript = media_transcript.encode('utf-8')
|
media_transcript = media_transcript.encode('utf-8')
|
||||||
set_headers_etag(self, media_filename, media_file_type,
|
set_headers_etag(self, media_filename, media_file_type,
|
||||||
media_transcript, None,
|
media_transcript, None,
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ from fitnessFunctions import fitness_performance
|
||||||
from securemode import secure_mode
|
from securemode import secure_mode
|
||||||
from context import get_individual_post_context
|
from context import get_individual_post_context
|
||||||
from conversation import convthread_id_to_conversation_tag
|
from conversation import convthread_id_to_conversation_tag
|
||||||
|
from data import load_string
|
||||||
|
|
||||||
|
|
||||||
def _show_post_from_file(self, post_filename: str, liked_by: str,
|
def _show_post_from_file(self, post_filename: str, liked_by: str,
|
||||||
|
|
@ -308,12 +309,9 @@ def show_individual_post(self, ssml_getreq: bool, authorized: bool,
|
||||||
if not os.path.isfile(ssml_filename):
|
if not os.path.isfile(ssml_filename):
|
||||||
http_404(self, 74)
|
http_404(self, 74)
|
||||||
return True
|
return True
|
||||||
ssml_str = None
|
ssml_str = load_string(ssml_filename,
|
||||||
try:
|
'EX: unable to read ssml file ' +
|
||||||
with open(ssml_filename, 'r', encoding='utf-8') as fp_ssml:
|
ssml_filename)
|
||||||
ssml_str = fp_ssml.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to read ssml file ' + ssml_filename)
|
|
||||||
if ssml_str:
|
if ssml_str:
|
||||||
msg = ssml_str.encode('utf-8')
|
msg = ssml_str.encode('utf-8')
|
||||||
msglen = len(msg)
|
msglen = len(msg)
|
||||||
|
|
@ -661,12 +659,9 @@ def show_individual_at_post(self, ssml_getreq: bool, authorized: bool,
|
||||||
if not os.path.isfile(ssml_filename):
|
if not os.path.isfile(ssml_filename):
|
||||||
http_404(self, 67)
|
http_404(self, 67)
|
||||||
return True
|
return True
|
||||||
ssml_str = None
|
ssml_str = load_string(ssml_filename,
|
||||||
try:
|
'EX: unable to read ssml file 2 ' +
|
||||||
with open(ssml_filename, 'r', encoding='utf-8') as fp_ssml:
|
ssml_filename)
|
||||||
ssml_str = fp_ssml.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to read ssml file 2 ' + ssml_filename)
|
|
||||||
if ssml_str:
|
if ssml_str:
|
||||||
msg = ssml_str.encode('utf-8')
|
msg = ssml_str.encode('utf-8')
|
||||||
msglen = len(msg)
|
msglen = len(msg)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ from media import path_is_video
|
||||||
from media import path_is_audio
|
from media import path_is_audio
|
||||||
from daemon_utils import get_user_agent
|
from daemon_utils import get_user_agent
|
||||||
from daemon_utils import log_epicyon_instances
|
from daemon_utils import log_epicyon_instances
|
||||||
|
from data import load_string
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def daemon_http_head(self) -> None:
|
def daemon_http_head(self) -> None:
|
||||||
|
|
@ -118,13 +120,11 @@ def daemon_http_head(self) -> None:
|
||||||
last_modified_time.strftime(time_format_str)
|
last_modified_time.strftime(time_format_str)
|
||||||
media_tag_filename = media_filename + '.etag'
|
media_tag_filename = media_filename + '.etag'
|
||||||
if os.path.isfile(media_tag_filename):
|
if os.path.isfile(media_tag_filename):
|
||||||
try:
|
etag_str = load_string(media_tag_filename,
|
||||||
with open(media_tag_filename, 'r',
|
'EX: do_HEAD unable to read ' +
|
||||||
encoding='utf-8') as fp_efile:
|
media_tag_filename)
|
||||||
etag = fp_efile.read()
|
if etag_str:
|
||||||
except OSError:
|
etag = etag_str
|
||||||
print('EX: do_HEAD unable to read ' +
|
|
||||||
media_tag_filename)
|
|
||||||
else:
|
else:
|
||||||
media_binary = None
|
media_binary = None
|
||||||
try:
|
try:
|
||||||
|
|
@ -135,13 +135,9 @@ def daemon_http_head(self) -> None:
|
||||||
media_filename)
|
media_filename)
|
||||||
if media_binary:
|
if media_binary:
|
||||||
etag = md5(media_binary).hexdigest() # nosec
|
etag = md5(media_binary).hexdigest() # nosec
|
||||||
try:
|
save_string(etag, media_tag_filename,
|
||||||
with open(media_tag_filename, 'w+',
|
'EX: do_HEAD unable to write ' +
|
||||||
encoding='utf-8') as fp_efile:
|
media_tag_filename)
|
||||||
fp_efile.write(etag)
|
|
||||||
except OSError:
|
|
||||||
print('EX: do_HEAD unable to write ' +
|
|
||||||
media_tag_filename)
|
|
||||||
else:
|
else:
|
||||||
http_404(self, 151)
|
http_404(self, 151)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ from utils import get_nickname_from_actor
|
||||||
from utils import get_config_param
|
from utils import get_config_param
|
||||||
from httpheaders import redirect_headers
|
from httpheaders import redirect_headers
|
||||||
from content import extract_text_fields_in_post
|
from content import extract_text_fields_in_post
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def _links_update_edited(fields: {}, links_filename: str) -> None:
|
def _links_update_edited(fields: {}, links_filename: str) -> None:
|
||||||
|
|
@ -30,24 +31,16 @@ def _links_update_edited(fields: {}, links_filename: str) -> None:
|
||||||
if not links_str.endswith('\n'):
|
if not links_str.endswith('\n'):
|
||||||
links_str += '\n'
|
links_str += '\n'
|
||||||
links_str += fields['newColLink'] + '\n'
|
links_str += fields['newColLink'] + '\n'
|
||||||
try:
|
save_string(links_str, links_filename,
|
||||||
with open(links_filename, 'w+',
|
'EX: _links_update unable to write ' +
|
||||||
encoding='utf-8') as fp_links:
|
links_filename)
|
||||||
fp_links.write(links_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: _links_update unable to write ' +
|
|
||||||
links_filename)
|
|
||||||
else:
|
else:
|
||||||
if fields.get('newColLink'):
|
if fields.get('newColLink'):
|
||||||
# the text area is empty but there is a new link added
|
# the text area is empty but there is a new link added
|
||||||
links_str = fields['newColLink'] + '\n'
|
links_str = fields['newColLink'] + '\n'
|
||||||
try:
|
save_string(links_str, links_filename,
|
||||||
with open(links_filename, 'w+',
|
'EX: _links_update unable to write ' +
|
||||||
encoding='utf-8') as fp_links:
|
links_filename)
|
||||||
fp_links.write(links_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: _links_update unable to write ' +
|
|
||||||
links_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(links_filename):
|
if os.path.isfile(links_filename):
|
||||||
try:
|
try:
|
||||||
|
|
@ -65,13 +58,9 @@ def _links_update_about(fields: {}, allow_local_network_access: bool,
|
||||||
about_str = fields['editedAbout']
|
about_str = fields['editedAbout']
|
||||||
if not dangerous_markup(about_str,
|
if not dangerous_markup(about_str,
|
||||||
allow_local_network_access, []):
|
allow_local_network_access, []):
|
||||||
try:
|
save_string(about_str, about_filename,
|
||||||
with open(about_filename, 'w+',
|
'EX: unable to write about ' +
|
||||||
encoding='utf-8') as fp_about:
|
about_filename)
|
||||||
fp_about.write(about_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to write about ' +
|
|
||||||
about_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(about_filename):
|
if os.path.isfile(about_filename):
|
||||||
try:
|
try:
|
||||||
|
|
@ -89,11 +78,8 @@ def _links_update_tos(fields: {}, allow_local_network_access: bool,
|
||||||
tos_str = fields['editedTOS']
|
tos_str = fields['editedTOS']
|
||||||
if not dangerous_markup(tos_str,
|
if not dangerous_markup(tos_str,
|
||||||
allow_local_network_access, []):
|
allow_local_network_access, []):
|
||||||
try:
|
save_string(tos_str, tos_filename,
|
||||||
with open(tos_filename, 'w+', encoding='utf-8') as fp_tos:
|
'EX: unable to write TOS ' + tos_filename)
|
||||||
fp_tos.write(tos_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to write TOS ' + tos_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(tos_filename):
|
if os.path.isfile(tos_filename):
|
||||||
try:
|
try:
|
||||||
|
|
@ -109,13 +95,9 @@ def _links_update_sepcification(fields: {},
|
||||||
"""
|
"""
|
||||||
if fields.get('editedSpecification'):
|
if fields.get('editedSpecification'):
|
||||||
specification_str = fields['editedSpecification']
|
specification_str = fields['editedSpecification']
|
||||||
try:
|
save_string(specification_str, specification_filename,
|
||||||
with open(specification_filename, 'w+',
|
'EX: unable to write specification ' +
|
||||||
encoding='utf-8') as fp_specification:
|
specification_filename)
|
||||||
fp_specification.write(specification_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to write specification ' +
|
|
||||||
specification_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(specification_filename):
|
if os.path.isfile(specification_filename):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ from flags import is_system_account
|
||||||
from person import person_upgrade_actor
|
from person import person_upgrade_actor
|
||||||
from person import activate_account2
|
from person import activate_account2
|
||||||
from person import register_account
|
from person import register_account
|
||||||
|
from data import load_string
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def post_login_screen(self, calling_domain: str, cookie: str,
|
def post_login_screen(self, calling_domain: str, cookie: str,
|
||||||
|
|
@ -180,21 +182,15 @@ def post_login_screen(self, calling_domain: str, cookie: str,
|
||||||
acct_dir(base_dir, login_nickname, domain) + '/.salt'
|
acct_dir(base_dir, login_nickname, domain) + '/.salt'
|
||||||
salt = create_password(32)
|
salt = create_password(32)
|
||||||
if os.path.isfile(salt_filename):
|
if os.path.isfile(salt_filename):
|
||||||
try:
|
salt_str = load_string(salt_filename,
|
||||||
with open(salt_filename, 'r',
|
'EX: Unable to read salt for ' +
|
||||||
encoding='utf-8') as fp_salt:
|
login_nickname + ' [ex]')
|
||||||
salt = fp_salt.read()
|
if salt_str:
|
||||||
except OSError as ex:
|
salt = salt_str
|
||||||
print('EX: Unable to read salt for ' +
|
|
||||||
login_nickname + ' ' + str(ex))
|
|
||||||
else:
|
else:
|
||||||
try:
|
save_string(salt, salt_filename,
|
||||||
with open(salt_filename, 'w+',
|
'EX: Unable to save salt for ' +
|
||||||
encoding='utf-8') as fp_salt:
|
login_nickname + ' [ex]')
|
||||||
fp_salt.write(salt)
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: Unable to save salt for ' +
|
|
||||||
login_nickname + ' ' + str(ex))
|
|
||||||
|
|
||||||
token_text = login_nickname + login_password + salt
|
token_text = login_nickname + login_password + salt
|
||||||
token = sha256(token_text.encode('utf-8')).hexdigest()
|
token = sha256(token_text.encode('utf-8')).hexdigest()
|
||||||
|
|
@ -202,13 +198,9 @@ def post_login_screen(self, calling_domain: str, cookie: str,
|
||||||
login_handle = login_nickname + '@' + domain
|
login_handle = login_nickname + '@' + domain
|
||||||
token_filename = \
|
token_filename = \
|
||||||
data_dir(base_dir) + '/' + login_handle + '/.token'
|
data_dir(base_dir) + '/' + login_handle + '/.token'
|
||||||
try:
|
save_string(token, token_filename,
|
||||||
with open(token_filename, 'w+',
|
'EX: Unable to save token for ' +
|
||||||
encoding='utf-8') as fp_tok:
|
login_nickname + ' [ex]')
|
||||||
fp_tok.write(token)
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: Unable to save token for ' +
|
|
||||||
login_nickname + ' ' + str(ex))
|
|
||||||
|
|
||||||
dir_str = data_dir(base_dir)
|
dir_str = data_dir(base_dir)
|
||||||
person_upgrade_actor(base_dir, None,
|
person_upgrade_actor(base_dir, None,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ from timeFunctions import date_from_string_format
|
||||||
from httpheaders import redirect_headers
|
from httpheaders import redirect_headers
|
||||||
from content import extract_text_fields_in_post
|
from content import extract_text_fields_in_post
|
||||||
from content import load_dogwhistles
|
from content import load_dogwhistles
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def newswire_update(self, calling_domain: str, cookie: str,
|
def newswire_update(self, calling_domain: str, cookie: str,
|
||||||
|
|
@ -116,22 +117,14 @@ def newswire_update(self, calling_domain: str, cookie: str,
|
||||||
if not newswire_str.endswith('\n'):
|
if not newswire_str.endswith('\n'):
|
||||||
newswire_str += '\n'
|
newswire_str += '\n'
|
||||||
newswire_str += fields['newNewswireFeed'] + '\n'
|
newswire_str += fields['newNewswireFeed'] + '\n'
|
||||||
try:
|
save_string(newswire_str, newswire_filename,
|
||||||
with open(newswire_filename, 'w+',
|
'EX: unable to write ' + newswire_filename)
|
||||||
encoding='utf-8') as fp_news:
|
|
||||||
fp_news.write(newswire_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to write ' + newswire_filename)
|
|
||||||
else:
|
else:
|
||||||
if fields.get('newNewswireFeed'):
|
if fields.get('newNewswireFeed'):
|
||||||
# the text area is empty but there is a new feed added
|
# the text area is empty but there is a new feed added
|
||||||
newswire_str = fields['newNewswireFeed'] + '\n'
|
newswire_str = fields['newNewswireFeed'] + '\n'
|
||||||
try:
|
save_string(newswire_str, newswire_filename,
|
||||||
with open(newswire_filename, 'w+',
|
'EX: unable to write ' + newswire_filename)
|
||||||
encoding='utf-8') as fp_news:
|
|
||||||
fp_news.write(newswire_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: unable to write ' + newswire_filename)
|
|
||||||
else:
|
else:
|
||||||
# text area has been cleared and there is no new feed
|
# text area has been cleared and there is no new feed
|
||||||
if os.path.isfile(newswire_filename):
|
if os.path.isfile(newswire_filename):
|
||||||
|
|
@ -145,13 +138,10 @@ def newswire_update(self, calling_domain: str, cookie: str,
|
||||||
filter_newswire_filename = \
|
filter_newswire_filename = \
|
||||||
data_dir(base_dir) + '/' + 'news@' + domain + '/filters.txt'
|
data_dir(base_dir) + '/' + 'news@' + domain + '/filters.txt'
|
||||||
if fields.get('filteredWordsNewswire'):
|
if fields.get('filteredWordsNewswire'):
|
||||||
try:
|
save_string(fields['filteredWordsNewswire'],
|
||||||
with open(filter_newswire_filename, 'w+',
|
filter_newswire_filename,
|
||||||
encoding='utf-8') as fp_filter:
|
'EX: newswire_update unable to write ' +
|
||||||
fp_filter.write(fields['filteredWordsNewswire'])
|
filter_newswire_filename)
|
||||||
except OSError:
|
|
||||||
print('EX: newswire_update unable to write ' +
|
|
||||||
filter_newswire_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(filter_newswire_filename):
|
if os.path.isfile(filter_newswire_filename):
|
||||||
try:
|
try:
|
||||||
|
|
@ -163,36 +153,26 @@ def newswire_update(self, calling_domain: str, cookie: str,
|
||||||
# save dogwhistle words list
|
# save dogwhistle words list
|
||||||
dogwhistles_filename = data_dir(base_dir) + '/dogwhistles.txt'
|
dogwhistles_filename = data_dir(base_dir) + '/dogwhistles.txt'
|
||||||
if fields.get('dogwhistleWords'):
|
if fields.get('dogwhistleWords'):
|
||||||
try:
|
save_string(fields['dogwhistleWords'],
|
||||||
with open(dogwhistles_filename, 'w+',
|
dogwhistles_filename,
|
||||||
encoding='utf-8') as fp_dogwhistles:
|
'EX: newswire_update unable to write 2 ' +
|
||||||
fp_dogwhistles.write(fields['dogwhistleWords'])
|
dogwhistles_filename)
|
||||||
except OSError:
|
|
||||||
print('EX: newswire_update unable to write 2 ' +
|
|
||||||
dogwhistles_filename)
|
|
||||||
self.server.dogwhistles = \
|
self.server.dogwhistles = \
|
||||||
load_dogwhistles(dogwhistles_filename)
|
load_dogwhistles(dogwhistles_filename)
|
||||||
else:
|
else:
|
||||||
# save an empty file
|
# save an empty file
|
||||||
try:
|
save_string('', dogwhistles_filename,
|
||||||
with open(dogwhistles_filename, 'w+',
|
'EX: newswire_update unable unable to write 3 ' +
|
||||||
encoding='utf-8') as fp_dogwhistles:
|
dogwhistles_filename)
|
||||||
fp_dogwhistles.write('')
|
|
||||||
except OSError:
|
|
||||||
print('EX: newswire_update unable unable to write 3 ' +
|
|
||||||
dogwhistles_filename)
|
|
||||||
self.server.dogwhistles = {}
|
self.server.dogwhistles = {}
|
||||||
|
|
||||||
# save news tagging rules
|
# save news tagging rules
|
||||||
hashtag_rules_filename = data_dir(base_dir) + '/hashtagrules.txt'
|
hashtag_rules_filename = data_dir(base_dir) + '/hashtagrules.txt'
|
||||||
if fields.get('hashtagRulesList'):
|
if fields.get('hashtagRulesList'):
|
||||||
try:
|
save_string(fields['hashtagRulesList'],
|
||||||
with open(hashtag_rules_filename, 'w+',
|
hashtag_rules_filename,
|
||||||
encoding='utf-8') as fp_rules:
|
'EX: newswire_update unable to write 4 ' +
|
||||||
fp_rules.write(fields['hashtagRulesList'])
|
hashtag_rules_filename)
|
||||||
except OSError:
|
|
||||||
print('EX: newswire_update unable to write 4 ' +
|
|
||||||
hashtag_rules_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(hashtag_rules_filename):
|
if os.path.isfile(hashtag_rules_filename):
|
||||||
try:
|
try:
|
||||||
|
|
@ -206,13 +186,9 @@ def newswire_update(self, calling_domain: str, cookie: str,
|
||||||
newswire_trusted = fields['trustedNewswire']
|
newswire_trusted = fields['trustedNewswire']
|
||||||
if not newswire_trusted.endswith('\n'):
|
if not newswire_trusted.endswith('\n'):
|
||||||
newswire_trusted += '\n'
|
newswire_trusted += '\n'
|
||||||
try:
|
save_string(newswire_trusted, newswire_tusted_filename,
|
||||||
with open(newswire_tusted_filename, 'w+',
|
'EX: newswire_update unable to write 5 ' +
|
||||||
encoding='utf-8') as fp_trust:
|
newswire_tusted_filename)
|
||||||
fp_trust.write(newswire_trusted)
|
|
||||||
except OSError:
|
|
||||||
print('EX: newswire_update unable to write 5 ' +
|
|
||||||
newswire_tusted_filename)
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(newswire_tusted_filename):
|
if os.path.isfile(newswire_tusted_filename):
|
||||||
try:
|
try:
|
||||||
|
|
@ -315,13 +291,9 @@ def citations_update(self, calling_domain: str, cookie: str,
|
||||||
citations_str += citation_date + '\n'
|
citations_str += citation_date + '\n'
|
||||||
# save citations dates, so that they can be added when
|
# save citations dates, so that they can be added when
|
||||||
# reloading the newblog screen
|
# reloading the newblog screen
|
||||||
try:
|
save_string(citations_str, citations_filename,
|
||||||
with open(citations_filename, 'w+',
|
'EX: citations_update unable to write ' +
|
||||||
encoding='utf-8') as fp_cit:
|
citations_filename)
|
||||||
fp_cit.write(citations_str)
|
|
||||||
except OSError:
|
|
||||||
print('EX: citations_update unable to write ' +
|
|
||||||
citations_filename)
|
|
||||||
|
|
||||||
# redirect back to the default timeline
|
# redirect back to the default timeline
|
||||||
redirect_headers(self, actor_str + '/newblog',
|
redirect_headers(self, actor_str + '/newblog',
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ from blocking import blocked_quote_toots_remove
|
||||||
from notifyOnPost import add_notify_on_post
|
from notifyOnPost import add_notify_on_post
|
||||||
from notifyOnPost import remove_notify_on_post
|
from notifyOnPost import remove_notify_on_post
|
||||||
from flags import is_moderator
|
from flags import is_moderator
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
def _person_options_page_number(options_confirm_params: str) -> int:
|
def _person_options_page_number(options_confirm_params: str) -> int:
|
||||||
|
|
@ -611,16 +612,9 @@ def _person_options_post_to_news(self, options_confirm_params: str,
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(account_dir):
|
if os.path.isdir(account_dir):
|
||||||
nw_filename = newswire_blocked_filename
|
nw_filename = newswire_blocked_filename
|
||||||
nw_written = False
|
if save_string('\n', nw_filename,
|
||||||
try:
|
'EX: _person_options_post_to_news unable ' +
|
||||||
with open(nw_filename, 'w+',
|
'to write ' + nw_filename + ' [ex]'):
|
||||||
encoding='utf-8') as fp_no:
|
|
||||||
fp_no.write('\n')
|
|
||||||
nw_written = True
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: _person_options_post_to_news unable ' +
|
|
||||||
'to write ' + nw_filename + ' ' + str(ex))
|
|
||||||
if nw_written:
|
|
||||||
refresh_newswire(base_dir)
|
refresh_newswire(base_dir)
|
||||||
users_path_str = \
|
users_path_str = \
|
||||||
users_path + '/' + default_timeline + \
|
users_path + '/' + default_timeline + \
|
||||||
|
|
@ -671,17 +665,10 @@ def _person_options_post_to_features(self, options_confirm_params: str,
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(account_dir):
|
if os.path.isdir(account_dir):
|
||||||
feat_filename = features_blocked_filename
|
feat_filename = features_blocked_filename
|
||||||
feat_written = False
|
if save_string('\n', feat_filename,
|
||||||
try:
|
'EX: _person_options_post_to_features ' +
|
||||||
with open(feat_filename, 'w+',
|
'unable to write ' + feat_filename +
|
||||||
encoding='utf-8') as fp_no:
|
' [ex]'):
|
||||||
fp_no.write('\n')
|
|
||||||
feat_written = True
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: _person_options_post_to_features ' +
|
|
||||||
'unable to write ' + feat_filename +
|
|
||||||
' ' + str(ex))
|
|
||||||
if feat_written:
|
|
||||||
refresh_newswire(base_dir)
|
refresh_newswire(base_dir)
|
||||||
users_path_str = \
|
users_path_str = \
|
||||||
users_path + '/' + default_timeline + \
|
users_path + '/' + default_timeline + \
|
||||||
|
|
@ -731,13 +718,9 @@ def _person_options_mod_news(self, options_confirm_params: str,
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(account_dir):
|
if os.path.isdir(account_dir):
|
||||||
nw_filename = newswire_mod_filename
|
nw_filename = newswire_mod_filename
|
||||||
try:
|
save_string('\n', nw_filename,
|
||||||
with open(nw_filename, 'w+',
|
'EX: _person_options_mod_news ' +
|
||||||
encoding='utf-8') as fp_mod:
|
'unable to write ' + nw_filename)
|
||||||
fp_mod.write('\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: _person_options_mod_news ' +
|
|
||||||
'unable to write ' + nw_filename)
|
|
||||||
users_path_str = \
|
users_path_str = \
|
||||||
users_path + '/' + default_timeline + \
|
users_path + '/' + default_timeline + \
|
||||||
'?page=' + str(page_number)
|
'?page=' + str(page_number)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue