mirror of https://gitlab.com/bashrc2/epicyon
Switch words in html
parent
23978ee799
commit
6bed85c595
29
content.py
29
content.py
|
@ -12,6 +12,35 @@ import email.parser
|
|||
from shutil import copyfile
|
||||
from utils import loadJson
|
||||
|
||||
def switchWords(baseDir: str,nickname: str,domain: str,content: str) -> str:
|
||||
"""Performs word replacements. eg. Trump -> The Orange Menace
|
||||
"""
|
||||
switchWordsFilename= \
|
||||
baseDir+'/accounts/'+nickname+'@'+domain+'/replacewords.txt'
|
||||
if not os.path.isfile(switchWordsFilename):
|
||||
return content
|
||||
with open(switchWordsFilename, 'r') as fp:
|
||||
for line in fp:
|
||||
replaceStr=line.replace('\n','')
|
||||
wordTransform=None
|
||||
if '->' in replaceStr:
|
||||
wordTransform=replaceStr.split('->')
|
||||
elif ':' in replaceStr:
|
||||
wordTransform=replaceStr.split(':')
|
||||
elif ',' in replaceStr:
|
||||
wordTransform=replaceStr.split(',')
|
||||
elif ';' in replaceStr:
|
||||
wordTransform=replaceStr.split(';')
|
||||
elif '-' in replaceStr:
|
||||
wordTransform=replaceStr.split('-')
|
||||
if not wordTransform:
|
||||
continue
|
||||
if len(wordTransform)==2:
|
||||
content= \
|
||||
content.replace(wordTransform[0].strip(), \
|
||||
wordTransform[1].strip())
|
||||
return content
|
||||
|
||||
def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
|
||||
"""Uses the tags to replace :emoji: with html image markup
|
||||
"""
|
||||
|
|
|
@ -53,6 +53,7 @@ from bookmarks import bookmarkedByPerson
|
|||
from announce import announcedByPerson
|
||||
from blocking import isBlocked
|
||||
from blocking import isBlockedHashtag
|
||||
from content import switchWords
|
||||
from content import getMentionsFromHtml
|
||||
from content import addHtmlTags
|
||||
from content import replaceEmojiFromTags
|
||||
|
@ -2668,6 +2669,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \
|
|||
if not postJsonObject['object'].get('content'):
|
||||
return ''
|
||||
objectContent=removeLongWords(postJsonObject['object']['content'],40,[])
|
||||
objectContent=switchWords(baseDir,nickname,domain,objectContent)
|
||||
if not postIsSensitive:
|
||||
contentStr=objectContent+attachmentStr
|
||||
contentStr=addEmbeddedElements(translate,contentStr)
|
||||
|
|
Loading…
Reference in New Issue