From 9851a0f1af26fbc401ecb655362b47c91fbcfa4e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 1 Mar 2021 21:26:34 +0000 Subject: [PATCH] Include any detected links within speaker endpoint --- inbox.py | 6 ++++-- speaker.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/inbox.py b/inbox.py index c62fe1a59..29128d6b3 100644 --- a/inbox.py +++ b/inbox.py @@ -2156,10 +2156,11 @@ def _updateSpeaker(baseDir: str, nickname: str, domain: str, return speakerFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + '/speaker.json' + detectedLinks = [] content = urllib.parse.unquote_plus(postJsonObject['object']['content']) content = html.unescape(content) content = removeHtml(htmlReplaceQuoteMarks(content)) - content = speakerReplaceLinks(content, translate) + content = speakerReplaceLinks(content, translate, detectedLinks) imageDescription = '' if postJsonObject['object'].get('attachment'): @@ -2186,7 +2187,8 @@ def _updateSpeaker(baseDir: str, nickname: str, domain: str, "name": speakerName, "summary": summary, "say": content, - "imageDescription": imageDescription + "imageDescription": imageDescription, + "detectedLinks": detectedLinks } saveJson(speakerJson, speakerFilename) diff --git a/speaker.py b/speaker.py index 9718d3afd..6665b4c12 100644 --- a/speaker.py +++ b/speaker.py @@ -33,7 +33,8 @@ def getSpeakerRange(displayName: str) -> int: return random.randint(300, 800) -def speakerReplaceLinks(sayText: str, translate: {}) -> str: +def speakerReplaceLinks(sayText: str, translate: {}, + detectedLinks: []) -> str: """Replaces any links in the given text with "link to [domain]". Instead of reading out potentially very long and meaningless links """ @@ -58,6 +59,7 @@ def speakerReplaceLinks(sayText: str, translate: {}) -> str: if '/' in domain: domain = domain.split('/')[0] replacements[domainFull] = '. ' + linkedStr + ' ' + domain + '.' + detectedLinks.append(domainFull) for replaceStr, newStr in replacements.items(): sayText = sayText.replace(replaceStr, newStr) return sayText