mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
d6f4bc15ba
commit
50ec0f6ce2
77
inbox.py
77
inbox.py
|
@ -10,12 +10,7 @@ import json
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import html
|
|
||||||
import urllib.parse
|
|
||||||
from linked_data_sig import verifyJsonSignature
|
from linked_data_sig import verifyJsonSignature
|
||||||
from utils import getDisplayName
|
|
||||||
from utils import getGenderFromBio
|
|
||||||
from utils import removeHtml
|
|
||||||
from utils import getConfigParam
|
from utils import getConfigParam
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
from utils import validPostDate
|
from utils import validPostDate
|
||||||
|
@ -82,11 +77,7 @@ from happening import saveEventPost
|
||||||
from delete import removeOldHashtags
|
from delete import removeOldHashtags
|
||||||
from categories import guessHashtagCategory
|
from categories import guessHashtagCategory
|
||||||
from context import hasValidContext
|
from context import hasValidContext
|
||||||
from content import htmlReplaceQuoteMarks
|
from speaker import updateSpeaker
|
||||||
from speaker import speakerReplaceLinks
|
|
||||||
from speaker import speakerPronounce
|
|
||||||
from speaker import speakerEndpointJson
|
|
||||||
from speaker import removeEmojiFromText
|
|
||||||
|
|
||||||
|
|
||||||
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
|
@ -1414,7 +1405,7 @@ def _receiveAnnounce(recentPostsCache: {},
|
||||||
lookupActor = lookupActor.split('/statuses/')[0]
|
lookupActor = lookupActor.split('/statuses/')[0]
|
||||||
|
|
||||||
if not os.path.isfile(postFilename + '.tts'):
|
if not os.path.isfile(postFilename + '.tts'):
|
||||||
_updateSpeaker(baseDir, nickname, domain,
|
updateSpeaker(baseDir, nickname, domain,
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, lookupActor)
|
translate, lookupActor)
|
||||||
ttsFile = open(postFilename + '.tts', "w+")
|
ttsFile = open(postFilename + '.tts', "w+")
|
||||||
|
@ -2155,68 +2146,6 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _updateSpeaker(baseDir: str, nickname: str, domain: str,
|
|
||||||
postJsonObject: {}, personCache: {},
|
|
||||||
translate: {}, announcingActor: str) -> None:
|
|
||||||
""" Generates a json file which can be used for TTS announcement
|
|
||||||
of incoming inbox posts
|
|
||||||
"""
|
|
||||||
if not postJsonObject.get('object'):
|
|
||||||
return
|
|
||||||
if not isinstance(postJsonObject['object'], dict):
|
|
||||||
return
|
|
||||||
if not postJsonObject['object'].get('content'):
|
|
||||||
return
|
|
||||||
if not isinstance(postJsonObject['object']['content'], str):
|
|
||||||
return
|
|
||||||
speakerFilename = \
|
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + '/speaker.json'
|
|
||||||
detectedLinks = []
|
|
||||||
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
|
|
||||||
content = html.unescape(content)
|
|
||||||
content = content.replace('<p>', '').replace('</p>', ' ')
|
|
||||||
content = removeHtml(htmlReplaceQuoteMarks(content))
|
|
||||||
content = speakerReplaceLinks(content, translate, detectedLinks)
|
|
||||||
content = speakerPronounce(baseDir, content, translate)
|
|
||||||
|
|
||||||
imageDescription = ''
|
|
||||||
if postJsonObject['object'].get('attachment'):
|
|
||||||
attachList = postJsonObject['object']['attachment']
|
|
||||||
if isinstance(attachList, list):
|
|
||||||
for img in attachList:
|
|
||||||
if not isinstance(img, dict):
|
|
||||||
continue
|
|
||||||
if img.get('name'):
|
|
||||||
if isinstance(img['name'], str):
|
|
||||||
imageDescription += \
|
|
||||||
img['name'] + '. '
|
|
||||||
|
|
||||||
summary = ''
|
|
||||||
if postJsonObject['object'].get('summary'):
|
|
||||||
if isinstance(postJsonObject['object']['summary'], str):
|
|
||||||
summary = \
|
|
||||||
urllib.parse.unquote_plus(postJsonObject['object']['summary'])
|
|
||||||
summary = html.unescape(summary)
|
|
||||||
|
|
||||||
speakerName = \
|
|
||||||
getDisplayName(baseDir, postJsonObject['actor'], personCache)
|
|
||||||
if not speakerName:
|
|
||||||
return
|
|
||||||
speakerName = removeEmojiFromText(speakerName)
|
|
||||||
gender = getGenderFromBio(baseDir, postJsonObject['actor'],
|
|
||||||
personCache, translate)
|
|
||||||
if announcingActor:
|
|
||||||
announcedNickname = getNicknameFromActor(announcingActor)
|
|
||||||
announcedDomain = getDomainFromActor(announcingActor)
|
|
||||||
announcedHandle = announcedNickname + '@' + announcedDomain
|
|
||||||
content = \
|
|
||||||
translate['announces'] + ' ' + announcedHandle + '. ' + content
|
|
||||||
speakerJson = speakerEndpointJson(speakerName, summary,
|
|
||||||
content, imageDescription,
|
|
||||||
detectedLinks, gender)
|
|
||||||
saveJson(speakerJson, speakerFilename)
|
|
||||||
|
|
||||||
|
|
||||||
def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
session, keyId: str, handle: str, messageJson: {},
|
session, keyId: str, handle: str, messageJson: {},
|
||||||
baseDir: str, httpPrefix: str, sendThreads: [],
|
baseDir: str, httpPrefix: str, sendThreads: [],
|
||||||
|
@ -2552,7 +2481,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
print('ERROR: unable to update ' + boxname + ' index')
|
print('ERROR: unable to update ' + boxname + ' index')
|
||||||
else:
|
else:
|
||||||
if boxname == 'inbox':
|
if boxname == 'inbox':
|
||||||
_updateSpeaker(baseDir, nickname, domain,
|
updateSpeaker(baseDir, nickname, domain,
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, None)
|
translate, None)
|
||||||
if not unitTest:
|
if not unitTest:
|
||||||
|
|
77
speaker.py
77
speaker.py
|
@ -7,11 +7,20 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import html
|
||||||
import random
|
import random
|
||||||
|
import urllib.parse
|
||||||
from auth import createBasicAuthHeader
|
from auth import createBasicAuthHeader
|
||||||
from session import getJson
|
from session import getJson
|
||||||
|
from utils import getDomainFromActor
|
||||||
|
from utils import getNicknameFromActor
|
||||||
|
from utils import getGenderFromBio
|
||||||
|
from utils import getDisplayName
|
||||||
|
from utils import removeHtml
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
|
from utils import saveJson
|
||||||
from utils import getFullDomain
|
from utils import getFullDomain
|
||||||
|
from content import htmlReplaceQuoteMarks
|
||||||
|
|
||||||
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
|
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
|
||||||
|
|
||||||
|
@ -52,7 +61,7 @@ def getSpeakerRange(displayName: str) -> int:
|
||||||
return random.randint(300, 800)
|
return random.randint(300, 800)
|
||||||
|
|
||||||
|
|
||||||
def speakerPronounce(baseDir: str, sayText: str, translate: {}) -> str:
|
def _speakerPronounce(baseDir: str, sayText: str, translate: {}) -> str:
|
||||||
"""Screen readers may not always pronounce correctly, so you
|
"""Screen readers may not always pronounce correctly, so you
|
||||||
can have a file which specifies conversions. File should contain
|
can have a file which specifies conversions. File should contain
|
||||||
line items such as:
|
line items such as:
|
||||||
|
@ -171,7 +180,7 @@ def _addSSMLemphasis(sayText: str) -> str:
|
||||||
return sayText
|
return sayText
|
||||||
|
|
||||||
|
|
||||||
def removeEmojiFromText(sayText: str) -> str:
|
def _removeEmojiFromText(sayText: str) -> str:
|
||||||
"""Removes :emoji: from the given text
|
"""Removes :emoji: from the given text
|
||||||
"""
|
"""
|
||||||
if '*' not in sayText:
|
if '*' not in sayText:
|
||||||
|
@ -222,7 +231,7 @@ def getSpeakerFromServer(baseDir: str, session,
|
||||||
return speakerJson
|
return speakerJson
|
||||||
|
|
||||||
|
|
||||||
def speakerEndpointJson(displayName: str, summary: str,
|
def _speakerEndpointJson(displayName: str, summary: str,
|
||||||
content: str, imageDescription: str,
|
content: str, imageDescription: str,
|
||||||
links: [], gender: str) -> {}:
|
links: [], gender: str) -> {}:
|
||||||
"""Returns a json endpoint for the TTS speaker
|
"""Returns a json endpoint for the TTS speaker
|
||||||
|
@ -312,3 +321,65 @@ def getSSMLbox(baseDir: str, path: str,
|
||||||
speakerJson['detectedLinks'],
|
speakerJson['detectedLinks'],
|
||||||
systemLanguage,
|
systemLanguage,
|
||||||
instanceTitle, gender)
|
instanceTitle, gender)
|
||||||
|
|
||||||
|
|
||||||
|
def updateSpeaker(baseDir: str, nickname: str, domain: str,
|
||||||
|
postJsonObject: {}, personCache: {},
|
||||||
|
translate: {}, announcingActor: str) -> None:
|
||||||
|
""" Generates a json file which can be used for TTS announcement
|
||||||
|
of incoming inbox posts
|
||||||
|
"""
|
||||||
|
if not postJsonObject.get('object'):
|
||||||
|
return
|
||||||
|
if not isinstance(postJsonObject['object'], dict):
|
||||||
|
return
|
||||||
|
if not postJsonObject['object'].get('content'):
|
||||||
|
return
|
||||||
|
if not isinstance(postJsonObject['object']['content'], str):
|
||||||
|
return
|
||||||
|
speakerFilename = \
|
||||||
|
baseDir + '/accounts/' + nickname + '@' + domain + '/speaker.json'
|
||||||
|
detectedLinks = []
|
||||||
|
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
|
||||||
|
content = html.unescape(content)
|
||||||
|
content = content.replace('<p>', '').replace('</p>', ' ')
|
||||||
|
content = removeHtml(htmlReplaceQuoteMarks(content))
|
||||||
|
content = speakerReplaceLinks(content, translate, detectedLinks)
|
||||||
|
content = _speakerPronounce(baseDir, content, translate)
|
||||||
|
|
||||||
|
imageDescription = ''
|
||||||
|
if postJsonObject['object'].get('attachment'):
|
||||||
|
attachList = postJsonObject['object']['attachment']
|
||||||
|
if isinstance(attachList, list):
|
||||||
|
for img in attachList:
|
||||||
|
if not isinstance(img, dict):
|
||||||
|
continue
|
||||||
|
if img.get('name'):
|
||||||
|
if isinstance(img['name'], str):
|
||||||
|
imageDescription += \
|
||||||
|
img['name'] + '. '
|
||||||
|
|
||||||
|
summary = ''
|
||||||
|
if postJsonObject['object'].get('summary'):
|
||||||
|
if isinstance(postJsonObject['object']['summary'], str):
|
||||||
|
summary = \
|
||||||
|
urllib.parse.unquote_plus(postJsonObject['object']['summary'])
|
||||||
|
summary = html.unescape(summary)
|
||||||
|
|
||||||
|
speakerName = \
|
||||||
|
getDisplayName(baseDir, postJsonObject['actor'], personCache)
|
||||||
|
if not speakerName:
|
||||||
|
return
|
||||||
|
speakerName = _removeEmojiFromText(speakerName)
|
||||||
|
gender = getGenderFromBio(baseDir, postJsonObject['actor'],
|
||||||
|
personCache, translate)
|
||||||
|
if announcingActor:
|
||||||
|
announcedNickname = getNicknameFromActor(announcingActor)
|
||||||
|
announcedDomain = getDomainFromActor(announcingActor)
|
||||||
|
announcedHandle = announcedNickname + '@' + announcedDomain
|
||||||
|
content = \
|
||||||
|
translate['announces'] + ' ' + announcedHandle + '. ' + content
|
||||||
|
speakerJson = _speakerEndpointJson(speakerName, summary,
|
||||||
|
content, imageDescription,
|
||||||
|
detectedLinks, gender)
|
||||||
|
saveJson(speakerJson, speakerFilename)
|
||||||
|
|
Loading…
Reference in New Issue