Include any detected links within speaker endpoint

merge-requests/30/head
Bob Mottram 2021-03-01 21:26:34 +00:00
parent eabfdd367c
commit 9851a0f1af
2 changed files with 7 additions and 3 deletions

View File

@ -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)

View File

@ -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