diff --git a/content.py b/content.py index e823bfc1b..303cce70d 100644 --- a/content.py +++ b/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 """ diff --git a/webinterface.py b/webinterface.py index c7cf253e5..ed71604c3 100644 --- a/webinterface.py +++ b/webinterface.py @@ -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)