From b4b6af70f5d1af0eeddaa6306f09fe24780cca85 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 1 Mar 2021 21:20:06 +0000 Subject: [PATCH] Replace web links with shorter versions for the speaker interface --- inbox.py | 8 ++++++-- speaker.py | 30 ++++++++++++++++++++++++++++++ translations/ar.json | 3 ++- translations/ca.json | 3 ++- translations/cy.json | 3 ++- translations/de.json | 3 ++- translations/en.json | 3 ++- translations/es.json | 3 ++- translations/fr.json | 3 ++- translations/ga.json | 3 ++- translations/hi.json | 3 ++- translations/it.json | 3 ++- translations/ja.json | 3 ++- translations/oc.json | 3 ++- translations/pt.json | 3 ++- translations/ru.json | 3 ++- translations/zh.json | 3 ++- 17 files changed, 66 insertions(+), 17 deletions(-) diff --git a/inbox.py b/inbox.py index 1239f490f..c62fe1a59 100644 --- a/inbox.py +++ b/inbox.py @@ -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') diff --git a/speaker.py b/speaker.py index ea3df1141..a6bc1e347 100644 --- a/speaker.py +++ b/speaker.py @@ -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, diff --git a/translations/ar.json b/translations/ar.json index 5ced3e7f3..362cafdc9 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -373,5 +373,6 @@ "Pixel": "بكسل", "DM bounce": "يتم قبول الرسائل فقط من الحسابات المتبعة", "Next": "التالي", - "Preview": "معاينة" + "Preview": "معاينة", + "Linked": "رابط موقع" } diff --git a/translations/ca.json b/translations/ca.json index 289209daa..31a088dd2 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -373,5 +373,6 @@ "Pixel": "Pixel", "DM bounce": "Els missatges només s’accepten des dels comptes seguits", "Next": "Pròxim", - "Preview": "Vista prèvia" + "Preview": "Vista prèvia", + "Linked": "enllaç web" } diff --git a/translations/cy.json b/translations/cy.json index e113a37ae..a7dea2397 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -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" } diff --git a/translations/de.json b/translations/de.json index 6b5cfd4a8..b6514707b 100644 --- a/translations/de.json +++ b/translations/de.json @@ -373,5 +373,6 @@ "Pixel": "Pixel", "DM bounce": "Nachrichten werden nur von folgenden Konten akzeptiert", "Next": "Nächster", - "Preview": "Vorschau" + "Preview": "Vorschau", + "Linked": "Weblink" } diff --git a/translations/en.json b/translations/en.json index a80f3da5f..39d21a55a 100644 --- a/translations/en.json +++ b/translations/en.json @@ -373,5 +373,6 @@ "Pixel": "Pixel", "DM bounce": "Messages are only accepted from followed accounts", "Next": "Next", - "Preview": "Preview" + "Preview": "Preview", + "Linked": "Web linked" } diff --git a/translations/es.json b/translations/es.json index a18c27d52..0170be798 100644 --- a/translations/es.json +++ b/translations/es.json @@ -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" } diff --git a/translations/fr.json b/translations/fr.json index e0a42b4c2..68887c1a5 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -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" } diff --git a/translations/ga.json b/translations/ga.json index f459bc1b0..a9ff8814c 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -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" } diff --git a/translations/hi.json b/translations/hi.json index 13e65d5f3..ae79a7f7e 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -373,5 +373,6 @@ "Pixel": "पिक्सेल", "DM bounce": "संदेश केवल अनुसरण किए गए खातों से स्वीकार किए जाते हैं", "Next": "अगला", - "Preview": "पूर्वावलोकन" + "Preview": "पूर्वावलोकन", + "Linked": "वेब लिंक" } diff --git a/translations/it.json b/translations/it.json index 8446396c8..1ee936313 100644 --- a/translations/it.json +++ b/translations/it.json @@ -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" } diff --git a/translations/ja.json b/translations/ja.json index f8ee10565..14d2e1b25 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -373,5 +373,6 @@ "Pixel": "ピクセル", "DM bounce": "メッセージはフォローされているアカウントからのみ受け付けられます", "Next": "次", - "Preview": "プレビュー" + "Preview": "プレビュー", + "Linked": "ウェブリンク" } diff --git a/translations/oc.json b/translations/oc.json index e597567f2..f40e42213 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -369,5 +369,6 @@ "Pixel": "Pixel", "DM bounce": "Messages are only accepted from followed accounts", "Next": "Next", - "Preview": "Preview" + "Preview": "Preview", + "Linked": "Web link" } diff --git a/translations/pt.json b/translations/pt.json index 10e0bcd8b..7b5251016 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -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" } diff --git a/translations/ru.json b/translations/ru.json index bf1f5129b..4273fe15a 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -373,5 +373,6 @@ "Pixel": "Пиксель", "DM bounce": "Сообщения принимаются только от следующих аккаунтов", "Next": "Следующий", - "Preview": "Предварительный просмотр" + "Preview": "Предварительный просмотр", + "Linked": "интернет-ссылка" } diff --git a/translations/zh.json b/translations/zh.json index 9b09b3300..18cacf995 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -373,5 +373,6 @@ "Pixel": "像素点", "DM bounce": "仅接受来自后续帐户的邮件", "Next": "下一个", - "Preview": "预览" + "Preview": "预览", + "Linked": "网页链接" }