mirror of https://gitlab.com/bashrc2/epicyon
main
commit
9d0ee83260
|
@ -807,7 +807,9 @@ def _read_local_box_post(session, nickname: str, domain: str,
|
||||||
_text_only_content(content)
|
_text_only_content(content)
|
||||||
content += _get_image_description(post_json_object2)
|
content += _get_image_description(post_json_object2)
|
||||||
message_str, _ = \
|
message_str, _ = \
|
||||||
speakable_text(base_dir, content, translate)
|
speakable_text(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
base_dir, content, translate)
|
||||||
say_str = content
|
say_str = content
|
||||||
_say_command(say_str, message_str, screenreader,
|
_say_command(say_str, message_str, screenreader,
|
||||||
system_language, espeak)
|
system_language, espeak)
|
||||||
|
@ -837,7 +839,9 @@ def _read_local_box_post(session, nickname: str, domain: str,
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
content = _safe_message(content)
|
content = _safe_message(content)
|
||||||
message_str, _ = speakable_text(base_dir, content, translate)
|
message_str, _ = speakable_text(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
base_dir, content, translate)
|
||||||
|
|
||||||
if screenreader:
|
if screenreader:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
@ -870,7 +874,9 @@ def _read_local_box_post(session, nickname: str, domain: str,
|
||||||
return post_json_object
|
return post_json_object
|
||||||
|
|
||||||
|
|
||||||
def _desktop_show_actor(base_dir: str, actor_json: {}, translate: {},
|
def _desktop_show_actor(http_prefix: str,
|
||||||
|
nickname: str, domain: str, domain_full: str,
|
||||||
|
base_dir: str, actor_json: {}, translate: {},
|
||||||
system_language: str, screenreader: str,
|
system_language: str, screenreader: str,
|
||||||
espeak) -> None:
|
espeak) -> None:
|
||||||
"""Shows information for the given actor
|
"""Shows information for the given actor
|
||||||
|
@ -901,16 +907,20 @@ def _desktop_show_actor(base_dir: str, actor_json: {}, translate: {},
|
||||||
if actor_json.get('summary'):
|
if actor_json.get('summary'):
|
||||||
say_str = html.unescape(remove_html(actor_json['summary']))
|
say_str = html.unescape(remove_html(actor_json['summary']))
|
||||||
say_str = say_str.replace('"', "'")
|
say_str = say_str.replace('"', "'")
|
||||||
say_str2 = speakable_text(base_dir, say_str, translate)[0]
|
say_str2 = speakable_text(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
base_dir, say_str, translate)[0]
|
||||||
_say_command(say_str, say_str2, screenreader, system_language, espeak)
|
_say_command(say_str, say_str2, screenreader, system_language, espeak)
|
||||||
|
|
||||||
|
|
||||||
def _desktop_show_profile(session, nickname: str, domain: str,
|
def _desktop_show_profile(session, nickname: str,
|
||||||
|
domain: str, domain_full: str,
|
||||||
base_dir: str, index: int, box_json: {},
|
base_dir: str, index: int, box_json: {},
|
||||||
system_language: str,
|
system_language: str,
|
||||||
screenreader: str, espeak,
|
screenreader: str, espeak,
|
||||||
translate: {}, post_json_object: {},
|
translate: {}, post_json_object: {},
|
||||||
signing_priv_key_pem: str) -> {}:
|
signing_priv_key_pem: str,
|
||||||
|
http_prefix: str) -> {}:
|
||||||
"""Shows the profile of the actor for the given post
|
"""Shows the profile of the actor for the given post
|
||||||
Returns the actor json
|
Returns the actor json
|
||||||
"""
|
"""
|
||||||
|
@ -947,17 +957,21 @@ def _desktop_show_profile(session, nickname: str, domain: str,
|
||||||
get_actor_json(domain, actor, is_http, is_gnunet, is_ipfs, is_ipns,
|
get_actor_json(domain, actor, is_http, is_gnunet, is_ipfs, is_ipns,
|
||||||
False, True, signing_priv_key_pem, session)
|
False, True, signing_priv_key_pem, session)
|
||||||
|
|
||||||
_desktop_show_actor(base_dir, actor_json, translate,
|
_desktop_show_actor(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
base_dir, actor_json, translate,
|
||||||
system_language, screenreader, espeak)
|
system_language, screenreader, espeak)
|
||||||
|
|
||||||
return actor_json
|
return actor_json
|
||||||
|
|
||||||
|
|
||||||
def _desktop_show_profile_from_handle(session, domain: str, base_dir: str,
|
def _desktop_show_profile_from_handle(session, nickname: str, domain: str,
|
||||||
|
domain_full: str, base_dir: str,
|
||||||
handle: str, system_language: str,
|
handle: str, system_language: str,
|
||||||
screenreader: str, espeak,
|
screenreader: str, espeak,
|
||||||
translate: {},
|
translate: {},
|
||||||
signing_priv_key_pem: str) -> {}:
|
signing_priv_key_pem: str,
|
||||||
|
http_prefix: str) -> {}:
|
||||||
"""Shows the profile for a handle
|
"""Shows the profile for a handle
|
||||||
Returns the actor json
|
Returns the actor json
|
||||||
"""
|
"""
|
||||||
|
@ -966,7 +980,8 @@ def _desktop_show_profile_from_handle(session, domain: str, base_dir: str,
|
||||||
False, True,
|
False, True,
|
||||||
signing_priv_key_pem, session)
|
signing_priv_key_pem, session)
|
||||||
|
|
||||||
_desktop_show_actor(base_dir, actor_json, translate,
|
_desktop_show_actor(http_prefix, nickname, domain, domain_full,
|
||||||
|
base_dir, actor_json, translate,
|
||||||
system_language, screenreader, espeak)
|
system_language, screenreader, espeak)
|
||||||
|
|
||||||
return actor_json
|
return actor_json
|
||||||
|
@ -1733,14 +1748,16 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
if command_str == 'profile':
|
if command_str == 'profile':
|
||||||
if post_json_object:
|
if post_json_object:
|
||||||
actor_json = \
|
actor_json = \
|
||||||
_desktop_show_profile(session, nickname, domain,
|
_desktop_show_profile(session, nickname,
|
||||||
|
domain, domain_full,
|
||||||
base_dir, post_index,
|
base_dir, post_index,
|
||||||
box_json,
|
box_json,
|
||||||
system_language,
|
system_language,
|
||||||
screenreader,
|
screenreader,
|
||||||
espeak, translate,
|
espeak, translate,
|
||||||
post_json_object,
|
post_json_object,
|
||||||
signing_priv_key_pem)
|
signing_priv_key_pem,
|
||||||
|
http_prefix)
|
||||||
else:
|
else:
|
||||||
post_index_str = '1'
|
post_index_str = '1'
|
||||||
else:
|
else:
|
||||||
|
@ -1750,13 +1767,15 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
profile_handle = post_index_str
|
profile_handle = post_index_str
|
||||||
_desktop_clear_screen()
|
_desktop_clear_screen()
|
||||||
_desktop_show_banner()
|
_desktop_show_banner()
|
||||||
_desktop_show_profile_from_handle(session, domain,
|
_desktop_show_profile_from_handle(session, nickname,
|
||||||
|
domain, domain_full,
|
||||||
base_dir,
|
base_dir,
|
||||||
profile_handle,
|
profile_handle,
|
||||||
system_language,
|
system_language,
|
||||||
screenreader,
|
screenreader,
|
||||||
espeak, translate,
|
espeak, translate,
|
||||||
signing_priv_key_pem)
|
signing_priv_key_pem,
|
||||||
|
http_prefix)
|
||||||
say_str = 'Press Enter to continue...'
|
say_str = 'Press Enter to continue...'
|
||||||
say_str2 = _highlight_text(say_str)
|
say_str2 = _highlight_text(say_str)
|
||||||
_say_command(say_str2, say_str,
|
_say_command(say_str2, say_str,
|
||||||
|
@ -1771,12 +1790,14 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
post_index_str = "1"
|
post_index_str = "1"
|
||||||
post_index = int(post_index_str)
|
post_index = int(post_index_str)
|
||||||
actor_json = \
|
actor_json = \
|
||||||
_desktop_show_profile(session, nickname, domain,
|
_desktop_show_profile(session, nickname,
|
||||||
|
domain, domain_full,
|
||||||
base_dir, post_index,
|
base_dir, post_index,
|
||||||
box_json,
|
box_json,
|
||||||
system_language, screenreader,
|
system_language, screenreader,
|
||||||
espeak, translate,
|
espeak, translate,
|
||||||
None, signing_priv_key_pem)
|
None, signing_priv_key_pem,
|
||||||
|
http_prefix)
|
||||||
say_str = 'Press Enter to continue...'
|
say_str = 'Press Enter to continue...'
|
||||||
say_str2 = _highlight_text(say_str)
|
say_str2 = _highlight_text(say_str)
|
||||||
_say_command(say_str2, say_str,
|
_say_command(say_str2, say_str,
|
||||||
|
@ -2553,7 +2574,9 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
get_base_content_from_post(post_json_object,
|
get_base_content_from_post(post_json_object,
|
||||||
system_language)
|
system_language)
|
||||||
message_str, detected_links = \
|
message_str, detected_links = \
|
||||||
speakable_text(base_dir, content, translate)
|
speakable_text(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
base_dir, content, translate)
|
||||||
link_opened = False
|
link_opened = False
|
||||||
for url in detected_links:
|
for url in detected_links:
|
||||||
if '://' in url:
|
if '://' in url:
|
||||||
|
|
35
speaker.py
35
speaker.py
|
@ -170,7 +170,9 @@ def _speaker_pronounce(base_dir: str, say_text: str, translate: {}) -> str:
|
||||||
return say_text
|
return say_text
|
||||||
|
|
||||||
|
|
||||||
def speaker_replace_links(say_text: str, translate: {},
|
def speaker_replace_links(http_prefix: str, nickname: str,
|
||||||
|
orig_domain: str, orig_domain_full: str,
|
||||||
|
say_text: str, translate: {},
|
||||||
detected_links: []) -> str:
|
detected_links: []) -> str:
|
||||||
"""Replaces any links in the given text with "link to [domain]".
|
"""Replaces any links in the given text with "link to [domain]".
|
||||||
Instead of reading out potentially very long and meaningless links
|
Instead of reading out potentially very long and meaningless links
|
||||||
|
@ -181,6 +183,7 @@ def speaker_replace_links(say_text: str, translate: {},
|
||||||
text = text.replace(char, ' ')
|
text = text.replace(char, ' ')
|
||||||
text = text.replace('__v=', '?v=')
|
text = text.replace('__v=', '?v=')
|
||||||
replacements = {}
|
replacements = {}
|
||||||
|
replacements_hashtags = {}
|
||||||
words_list = text.split(' ')
|
words_list = text.split(' ')
|
||||||
if translate.get('Linked'):
|
if translate.get('Linked'):
|
||||||
linked_str = translate['Linked']
|
linked_str = translate['Linked']
|
||||||
|
@ -216,13 +219,21 @@ def speaker_replace_links(say_text: str, translate: {},
|
||||||
if domain.startswith('www.'):
|
if domain.startswith('www.'):
|
||||||
domain = domain.replace('www.', '')
|
domain = domain.replace('www.', '')
|
||||||
replacements[domain_full] = '. ' + linked_str + ' ' + domain + '.'
|
replacements[domain_full] = '. ' + linked_str + ' ' + domain + '.'
|
||||||
|
if '/tags/' in domain_full and domain != orig_domain:
|
||||||
|
remote_hashtag_link = \
|
||||||
|
http_prefix + '://' + orig_domain_full + '/users/' + \
|
||||||
|
nickname + '?remotetag=' + domain_full.replace('/', '--')
|
||||||
|
detected_links.append(remote_hashtag_link)
|
||||||
|
else:
|
||||||
detected_links.append(domain_full)
|
detected_links.append(domain_full)
|
||||||
for replace_str, new_str in replacements.items():
|
for replace_str, new_str in replacements.items():
|
||||||
say_text = say_text.replace(replace_str, new_str)
|
say_text = say_text.replace(replace_str, new_str)
|
||||||
|
for replace_str, new_str in replacements_hashtags.items():
|
||||||
|
say_text = say_text.replace(replace_str, new_str)
|
||||||
return say_text.replace('..', '.')
|
return say_text.replace('..', '.')
|
||||||
|
|
||||||
|
|
||||||
def _add_ssm_lemphasis(say_text: str) -> str:
|
def _add_ssml_emphasis(say_text: str) -> str:
|
||||||
"""Adds emphasis to *emphasised* text
|
"""Adds emphasis to *emphasised* text
|
||||||
"""
|
"""
|
||||||
if '*' not in say_text:
|
if '*' not in say_text:
|
||||||
|
@ -341,7 +352,7 @@ def _speaker_endpoint_ssml(display_name: str, summary: str,
|
||||||
else:
|
else:
|
||||||
gender = 'neutral'
|
gender = 'neutral'
|
||||||
|
|
||||||
content = _add_ssm_lemphasis(content)
|
content = _add_ssml_emphasis(content)
|
||||||
voice_params = 'name="' + display_name + '" gender="' + gender + '"'
|
voice_params = 'name="' + display_name + '" gender="' + gender + '"'
|
||||||
if summary is None:
|
if summary is None:
|
||||||
summary = ''
|
summary = ''
|
||||||
|
@ -382,9 +393,11 @@ def get_ssml_box(base_dir: str, path: str,
|
||||||
gender, box_name)
|
gender, box_name)
|
||||||
|
|
||||||
|
|
||||||
def speakable_text(base_dir: str, content: str, translate: {}) -> (str, []):
|
def speakable_text(http_prefix: str,
|
||||||
|
nickname: str, domain: str, domain_full: str,
|
||||||
|
base_dir: str, content: str, translate: {}) -> (str, []):
|
||||||
"""Convert the given text to a speakable version
|
"""Convert the given text to a speakable version
|
||||||
which includes changes for prononciation
|
which includes changes for pronunciation
|
||||||
"""
|
"""
|
||||||
content = str(content)
|
content = str(content)
|
||||||
if is_pgp_encrypted(content):
|
if is_pgp_encrypted(content):
|
||||||
|
@ -395,7 +408,9 @@ def speakable_text(base_dir: str, content: str, translate: {}) -> (str, []):
|
||||||
content = content.replace(' <3', ' ' + translate['heart'])
|
content = content.replace(' <3', ' ' + translate['heart'])
|
||||||
content = remove_html(html_replace_quote_marks(content))
|
content = remove_html(html_replace_quote_marks(content))
|
||||||
detected_links = []
|
detected_links = []
|
||||||
content = speaker_replace_links(content, translate, detected_links)
|
content = speaker_replace_links(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
content, translate, detected_links)
|
||||||
# replace all double spaces
|
# replace all double spaces
|
||||||
while ' ' in content:
|
while ' ' in content:
|
||||||
content = content.replace(' ', ' ')
|
content = content.replace(' ', ' ')
|
||||||
|
@ -408,7 +423,7 @@ def speakable_text(base_dir: str, content: str, translate: {}) -> (str, []):
|
||||||
|
|
||||||
|
|
||||||
def _post_to_speaker_json(base_dir: str, http_prefix: str,
|
def _post_to_speaker_json(base_dir: str, http_prefix: str,
|
||||||
nickname: str, domain_full: str,
|
nickname: str, domain: str, domain_full: str,
|
||||||
post_json_object: {}, person_cache: {},
|
post_json_object: {}, person_cache: {},
|
||||||
translate: {}, announcing_actor: str,
|
translate: {}, announcing_actor: str,
|
||||||
theme_name: str) -> {}:
|
theme_name: str) -> {}:
|
||||||
|
@ -432,7 +447,9 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
|
||||||
if ' <3' in content:
|
if ' <3' in content:
|
||||||
content = content.replace(' <3', ' ' + translate['heart'])
|
content = content.replace(' <3', ' ' + translate['heart'])
|
||||||
content = remove_html(html_replace_quote_marks(content))
|
content = remove_html(html_replace_quote_marks(content))
|
||||||
content = speaker_replace_links(content, translate, detected_links)
|
content = speaker_replace_links(http_prefix,
|
||||||
|
nickname, domain, domain_full,
|
||||||
|
content, translate, detected_links)
|
||||||
# replace all double spaces
|
# replace all double spaces
|
||||||
while ' ' in content:
|
while ' ' in content:
|
||||||
content = content.replace(' ', ' ')
|
content = content.replace(' ', ' ')
|
||||||
|
@ -551,7 +568,7 @@ def update_speaker(base_dir: str, http_prefix: str,
|
||||||
"""
|
"""
|
||||||
speaker_json = \
|
speaker_json = \
|
||||||
_post_to_speaker_json(base_dir, http_prefix,
|
_post_to_speaker_json(base_dir, http_prefix,
|
||||||
nickname, domain_full,
|
nickname, domain, domain_full,
|
||||||
post_json_object, person_cache,
|
post_json_object, person_cache,
|
||||||
translate, announcing_actor,
|
translate, announcing_actor,
|
||||||
theme_name)
|
theme_name)
|
||||||
|
|
21
tests.py
21
tests.py
|
@ -5960,6 +5960,11 @@ def _test_extract_text_fields_from_post():
|
||||||
|
|
||||||
|
|
||||||
def _test_speaker_replace_link():
|
def _test_speaker_replace_link():
|
||||||
|
http_prefix = 'https'
|
||||||
|
nickname = 'mynick'
|
||||||
|
domain = 'mydomain'
|
||||||
|
domain_full = domain
|
||||||
|
|
||||||
print('testSpeakerReplaceLinks')
|
print('testSpeakerReplaceLinks')
|
||||||
text = 'The Tor Project: For Snowflake volunteers: If you use ' + \
|
text = 'The Tor Project: For Snowflake volunteers: If you use ' + \
|
||||||
'Firefox, Brave, or Chrome, our Snowflake extension turns ' + \
|
'Firefox, Brave, or Chrome, our Snowflake extension turns ' + \
|
||||||
|
@ -5970,13 +5975,27 @@ def _test_speaker_replace_link():
|
||||||
'how-to-help-running-snowflake/'
|
'how-to-help-running-snowflake/'
|
||||||
detected_links = []
|
detected_links = []
|
||||||
result = \
|
result = \
|
||||||
speaker_replace_links(text, {'Linked': 'Web link'}, detected_links)
|
speaker_replace_links(http_prefix, nickname, domain, domain_full,
|
||||||
|
text, {'Linked': 'Web link'}, detected_links)
|
||||||
assert len(detected_links) == 1
|
assert len(detected_links) == 1
|
||||||
assert detected_links[0] == \
|
assert detected_links[0] == \
|
||||||
'https://support.torproject.org/censorship/' + \
|
'https://support.torproject.org/censorship/' + \
|
||||||
'how-to-help-running-snowflake/'
|
'how-to-help-running-snowflake/'
|
||||||
assert 'Web link support.torproject.org' in result
|
assert 'Web link support.torproject.org' in result
|
||||||
|
|
||||||
|
remote_link = 'https://somedomain/tags/sometag'
|
||||||
|
text = 'Test with a hashtag ' + remote_link + ' link'
|
||||||
|
detected_links = []
|
||||||
|
result = \
|
||||||
|
speaker_replace_links(http_prefix, nickname, domain, domain_full,
|
||||||
|
text, {'Linked': 'Web link'}, detected_links)
|
||||||
|
assert len(detected_links) == 1
|
||||||
|
local_link = \
|
||||||
|
'https://' + domain_full + '/users/' + nickname + \
|
||||||
|
'?remotetag=' + remote_link.replace('/', '--')
|
||||||
|
assert detected_links[0] == local_link
|
||||||
|
assert 'Web link somedomain' in result
|
||||||
|
|
||||||
|
|
||||||
def _test_camel_case_split():
|
def _test_camel_case_split():
|
||||||
print('test_camel_case_split')
|
print('test_camel_case_split')
|
||||||
|
|
|
@ -1409,6 +1409,13 @@ def hashtag_search_json(nickname: str, domain: str, port: int,
|
||||||
'totalItems': 0,
|
'totalItems': 0,
|
||||||
'type': 'OrderedCollection'
|
'type': 'OrderedCollection'
|
||||||
}
|
}
|
||||||
|
hashtag_json['first'] = \
|
||||||
|
http_prefix + '://' + domain_full + '/tags/' + \
|
||||||
|
hashtag + '?page=1'
|
||||||
|
if page_number > 1:
|
||||||
|
hashtag_json['prev'] = \
|
||||||
|
http_prefix + '://' + domain_full + '/tags/' + \
|
||||||
|
hashtag + '?page=' + str(page_number - 1)
|
||||||
page_items = 0
|
page_items = 0
|
||||||
for index, _ in enumerate(lines):
|
for index, _ in enumerate(lines):
|
||||||
post_id = lines[index].strip('\n').strip('\r')
|
post_id = lines[index].strip('\n').strip('\r')
|
||||||
|
@ -1442,6 +1449,9 @@ def hashtag_search_json(nickname: str, domain: str, port: int,
|
||||||
hashtag_json['orderedItems'].append(id_str)
|
hashtag_json['orderedItems'].append(id_str)
|
||||||
hashtag_json['totalItems'] += 1
|
hashtag_json['totalItems'] += 1
|
||||||
if hashtag_json['totalItems'] >= posts_per_page:
|
if hashtag_json['totalItems'] >= posts_per_page:
|
||||||
|
hashtag_json['next'] = \
|
||||||
|
http_prefix + '://' + domain_full + '/tags/' + \
|
||||||
|
hashtag + '?page=' + str(page_number + 1)
|
||||||
break
|
break
|
||||||
|
|
||||||
return hashtag_json
|
return hashtag_json
|
||||||
|
|
Loading…
Reference in New Issue