Replace web links with shorter versions for the speaker interface

merge-requests/21/head
Bob Mottram 2021-03-01 21:20:06 +00:00
parent d5dc473e22
commit b4b6af70f5
17 changed files with 66 additions and 17 deletions

View File

@ -82,6 +82,7 @@ from delete import removeOldHashtags
from categories import guessHashtagCategory
from context import hasValidContext
from content import htmlReplaceQuoteMarks
from speaker import speakerReplaceLinks
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
@ -2140,7 +2141,8 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
def _updateSpeaker(baseDir: str, nickname: str, domain: str,
postJsonObject: {}, personCache: {}) -> None:
postJsonObject: {}, personCache: {},
translate: {}) -> None:
""" Generates a json file which can be used for TTS announcement
of incoming inbox posts
"""
@ -2157,6 +2159,7 @@ def _updateSpeaker(baseDir: str, nickname: str, domain: str,
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
content = html.unescape(content)
content = removeHtml(htmlReplaceQuoteMarks(content))
content = speakerReplaceLinks(content, translate)
imageDescription = ''
if postJsonObject['object'].get('attachment'):
@ -2524,7 +2527,8 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
else:
if boxname == 'inbox':
_updateSpeaker(baseDir, nickname, domain,
postJsonObject, personCache)
postJsonObject, personCache,
translate)
if not unitTest:
if debug:
print('Saving inbox post as html to cache')

View File

@ -33,6 +33,36 @@ def getSpeakerRange(displayName: str) -> int:
return random.randint(300, 800)
def speakerReplaceLinks(sayText: str, translate: {}) -> str:
"""Replaces any links in the given text with "link to [domain]".
Instead of reading out potentially very long and meaningless links
"""
removeChars = ('.', ',', ';', ':')
text = sayText
for ch in removeChars:
text = text.replace(ch, ' ')
replacements = {}
wordsList = text.split(' ')
linkedStr = translate['Linked']
for word in wordsList:
domain = None
domainFull = None
if 'https://' in word:
domain = word.split('https://')[1]
domainFull = 'https://' + domain
elif 'http://' in word:
domain = word.split('http://')[1]
domainFull = 'http://' + domain
if not domain:
continue
if '/' in domain:
domain = domain.split('/')[0]
replacements[domainFull] = '. ' + linkedStr + ' ' + domain + '.'
for replaceStr, newStr in replacements.items():
sayText = sayText.replace(replaceStr, newStr)
return sayText
def getSpeakerFromServer(baseDir: str, session,
nickname: str, password: str,
domain: str, port: int,

View File

@ -373,5 +373,6 @@
"Pixel": "بكسل",
"DM bounce": "يتم قبول الرسائل فقط من الحسابات المتبعة",
"Next": "التالي",
"Preview": "معاينة"
"Preview": "معاينة",
"Linked": "رابط موقع"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Els missatges només saccepten des dels comptes seguits",
"Next": "Pròxim",
"Preview": "Vista prèvia"
"Preview": "Vista prèvia",
"Linked": "enllaç web"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Dim ond o gyfrifon a ddilynir y derbynnir negeseuon",
"Next": "Nesaf",
"Preview": "Rhagolwg"
"Preview": "Rhagolwg",
"Linked": "Dolen we"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Nachrichten werden nur von folgenden Konten akzeptiert",
"Next": "Nächster",
"Preview": "Vorschau"
"Preview": "Vorschau",
"Linked": "Weblink"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Messages are only accepted from followed accounts",
"Next": "Next",
"Preview": "Preview"
"Preview": "Preview",
"Linked": "Web linked"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Solo se aceptan mensajes de cuentas seguidas",
"Next": "Próxima",
"Preview": "Avance"
"Preview": "Avance",
"Linked": "enlace web"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Les messages ne sont acceptés que des comptes suivis",
"Next": "Suivante",
"Preview": "Aperçu"
"Preview": "Aperçu",
"Linked": "lien Web"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Ní ghlactar le teachtaireachtaí ach ó chuntais a leanann",
"Next": "Ar Aghaidh",
"Preview": "Réamhamharc"
"Preview": "Réamhamharc",
"Linked": "Nasc gréasáin"
}

View File

@ -373,5 +373,6 @@
"Pixel": "पिक्सेल",
"DM bounce": "संदेश केवल अनुसरण किए गए खातों से स्वीकार किए जाते हैं",
"Next": "अगला",
"Preview": "पूर्वावलोकन"
"Preview": "पूर्वावलोकन",
"Linked": "वेब लिंक"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "I messaggi sono accettati solo dagli account seguiti",
"Next": "Il prossimo",
"Preview": "Anteprima"
"Preview": "Anteprima",
"Linked": "collegamento web"
}

View File

@ -373,5 +373,6 @@
"Pixel": "ピクセル",
"DM bounce": "メッセージはフォローされているアカウントからのみ受け付けられます",
"Next": "次",
"Preview": "プレビュー"
"Preview": "プレビュー",
"Linked": "ウェブリンク"
}

View File

@ -369,5 +369,6 @@
"Pixel": "Pixel",
"DM bounce": "Messages are only accepted from followed accounts",
"Next": "Next",
"Preview": "Preview"
"Preview": "Preview",
"Linked": "Web link"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Pixel",
"DM bounce": "Mensagens são aceitas apenas de contas seguidas",
"Next": "Próxima",
"Preview": "Antevisão"
"Preview": "Antevisão",
"Linked": "link da web"
}

View File

@ -373,5 +373,6 @@
"Pixel": "Пиксель",
"DM bounce": "Сообщения принимаются только от следующих аккаунтов",
"Next": "Следующий",
"Preview": "Предварительный просмотр"
"Preview": "Предварительный просмотр",
"Linked": "интернет-ссылка"
}

View File

@ -373,5 +373,6 @@
"Pixel": "像素点",
"DM bounce": "仅接受来自后续帐户的邮件",
"Next": "下一个",
"Preview": "预览"
"Preview": "预览",
"Linked": "网页链接"
}