Extra emoji fields

main
Bob Mottram 2020-02-21 10:19:02 +00:00
parent a7b0634d1e
commit cc0b6f48e2
3 changed files with 16 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import time
import email.parser
from shutil import copyfile
from utils import loadJson
from utils import fileLastModified
def switchWords(baseDir: str,nickname: str,domain: str,content: str) -> str:
"""Performs word replacements. eg. Trump -> The Orange Menace
@ -174,7 +175,10 @@ def loadEmojiDict(emojiDataFilename: str,emojiDict: {}) -> None:
emojiName=emojiName.split('..')[0]
emojiDict[emojiName.lower()]=emojiUnicode
def addEmoji(baseDir: str,wordStr: str,httpPrefix: str,domain: str,replaceEmoji: {},postTags: {},emojiDict: {}) -> bool:
def addEmoji(baseDir: str,wordStr: str, \
httpPrefix: str,domain: str, \
replaceEmoji: {},postTags: {}, \
emojiDict: {}) -> bool:
"""Detects Emoji and adds them to the replacements dict
Also updates the tags list to be added to the post
"""
@ -205,6 +209,8 @@ def addEmoji(baseDir: str,wordStr: str,httpPrefix: str,domain: str,replaceEmoji:
'url': emojiUrl
},
'name': ':'+emoji+':',
"updated": fileLastModified(emojiFilename),
"id": emojiUrl.replace('.png',''),
'type': 'Emoji'
}
return True
@ -395,7 +401,7 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
wordStr2=wordStr.split(':')[1]
if not emojiDict:
# emoji.json is generated so that it can be customized and the changes
# will be retained even if default_emoji.json is subsequently updated
# will be retained even if default_emoji.json is subsequently updated
if not os.path.isfile(baseDir+'/emoji/emoji.json'):
copyfile(baseDir+'/emoji/default_emoji.json',baseDir+'/emoji/emoji.json')
emojiDict=loadJson(baseDir+'/emoji/emoji.json')

View File

@ -1388,6 +1388,7 @@ def testAddEmoji(content: str,emojiStr:str):
tags=[]
for tagName,tag in hashtags.items():
tags.append(tag)
print(str(tags))
content=contentModified
contentModified=replaceEmojiFromTags(content,tags,'content')
assert 'img src' in contentModified

View File

@ -562,3 +562,10 @@ def updateRecentPostsCache(recentPostsCache: {},maxRecentPosts: int, \
recentPostsCache['html']={}
recentPostsCache['json'][postId]=json.dumps(postJsonObject)
recentPostsCache['html'][postId]=htmlStr
def fileLastModified(filename: str) -> str:
"""Returns the date when a file was last modified
"""
t = os.path.getmtime(filename)
modifiedTime=datetime.datetime.fromtimestamp(t)
return modifiedTime.strftime("%Y-%m-%dT%H:%M:%SZ")