Separate tag replacement functions

main2
Bob Mottram 2019-09-29 18:20:10 +01:00
parent 1740cfad80
commit 1b15e9ff43
2 changed files with 29 additions and 8 deletions

View File

@ -11,14 +11,35 @@ import time
import commentjson import commentjson
from shutil import copyfile from shutil import copyfile
def replaceEmojiFromTags(content: str,tag,messageType: str) -> str: def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
"""Uses the tags to replace :emoji: with html image markup """Uses the tags to replace :emoji: with html image markup
""" """
tagList=tag for tagItem in tag:
if isinstance(tag, dict): if not tagItem.get('type'):
tagList=tag.items() continue
if tagItem['type']!='Emoji':
for tagItem in tagList: continue
if not tagItem.get('name'):
continue
if not tagItem.get('icon'):
continue
if not tagItem['icon'].get('url'):
continue
if tagItem['name'] not in content:
continue
htmlClass='emoji'
if messageType=='post header':
htmlClass='emojiheader'
if messageType=='profile':
htmlClass='emojiprofile'
emojiHtml="<img src=\""+tagItem['icon']['url']+"\" alt=\""+tagItem['name'].replace(':','')+"\" align=\"middle\" class=\""+htmlClass+"\"/>"
content=content.replace(tagItem['name'],emojiHtml)
return content
def replaceEmojiFromTagsDict(content: str,tag: {},messageType: str) -> str:
"""Uses the tags dictionary to replace :emoji: with html image markup
"""
for tagName,tagItem in tag.items():
if not tagItem.get('type'): if not tagItem.get('type'):
continue continue
if tagItem['type']!='Emoji': if tagItem['type']!='Emoji':

View File

@ -41,7 +41,7 @@ from capabilities import getOcapFilename
from capabilities import capabilitiesUpdate from capabilities import capabilitiesUpdate
from media import attachMedia from media import attachMedia
from content import addHtmlTags from content import addHtmlTags
from content import replaceEmojiFromTags from content import replaceEmojiFromTagsDict
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from config import getConfigParam from config import getConfigParam
from blocking import isBlocked from blocking import isBlocked
@ -460,7 +460,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
nickname,domain,content, \ nickname,domain,content, \
mentionedRecipients, \ mentionedRecipients, \
hashtagsDict) hashtagsDict)
content=replaceEmojiFromTags(content,hashtagsDict,'content') content=replaceEmojiFromTagsDict(content,hashtagsDict,'content')
statusNumber,published = getStatusNumber() statusNumber,published = getStatusNumber()
postTo='https://www.w3.org/ns/activitystreams#Public' postTo='https://www.w3.org/ns/activitystreams#Public'