Emoji search

master
Bob Mottram 2019-08-19 20:02:28 +01:00
parent f9e89c0a05
commit 3fbc80c68b
2 changed files with 55 additions and 0 deletions

View File

@ -87,6 +87,7 @@ from webinterface import htmlGetLoginCredentials
from webinterface import htmlNewPost from webinterface import htmlNewPost
from webinterface import htmlFollowConfirm from webinterface import htmlFollowConfirm
from webinterface import htmlSearch from webinterface import htmlSearch
from webinterface import htmlSearchEmoji
from webinterface import htmlUnfollowConfirm from webinterface import htmlUnfollowConfirm
from webinterface import htmlProfileAfterSearch from webinterface import htmlProfileAfterSearch
from webinterface import htmlEditProfile from webinterface import htmlEditProfile
@ -2404,6 +2405,20 @@ class PubServer(BaseHTTPRequestHandler):
self.wfile.write(msg) self.wfile.write(msg)
self.server.POSTbusy=False self.server.POSTbusy=False
return return
elif searchStr.startswith(':') or \
searchStr.lower().strip('\n').endswith(' emoji'):
# eg. "cat emoji"
if searchStr.lower().strip('\n').endswith(' emoji'):
searchStr=searchStr.lower().strip('\n').replace(' emoji','')
# emoji search
emojiStr= \
htmlSearchEmoji(self.server.baseDir,searchStr)
if emojiStr:
msg=sharedItemsStr.encode('utf-8')
self._login_headers('text/html',len(msg))
self.wfile.write(msg)
self.server.POSTbusy=False
return
else: else:
# shared items search # shared items search
sharedItemsStr= \ sharedItemsStr= \

View File

@ -46,6 +46,46 @@ def getPersonAvatarUrl(personUrl: str,personCache: {}) -> str:
return personJson['icon']['url'] return personJson['icon']['url']
return None return None
def htmlSearchEmoji(baseDir: str,searchStr: str) -> str:
"""Search results for emoji
"""
searchStr=searchStr.lower().replace(':','').strip('\n')
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
emojiCSS=cssFile.read()
emojiLookupFilename=baseDir+'/emoji/emoji.json'
# create header
emojiForm=htmlHeader(emojiCSS)
emojiForm+='<center><h1>Emoji Search</h1></center>'
# does the lookup file exist?
if not os.path.isfile(emojiLookupFilename):
emojiForm+='<center><h5>No results</h5></center>'
emojiForm+=htmlFooter()
return emojiForm
with open(emojiLookupFilename, 'r') as fp:
emojiJson=commentjson.load(fp)
results={}
if emojiJson.get(searchStr):
# exact match
results[searchStr] = emojiJson[searchStr]+'.png'
else:
for emojiName,filename in emojiJson.items():
if searchStr in emojiName:
results[emojiName] = filename+'.png'
for emojiName,filename in emojiJson.items():
if emojiName in searchStr:
results[emojiName] = filename+'.png'
emojiForm+='<center>'
for emojiName,filename in results.items():
emojiForm+='<h5>:'+emojiName+':<img src="/emoji/'+filename+'"/></h5>'
emojiForm+='</center>'
emojiForm+=htmlFooter()
return emojiForm
def htmlSearchSharedItems(baseDir: str,searchStr: str,pageNumber: int,resultsPerPage: int,actor: str) -> str: def htmlSearchSharedItems(baseDir: str,searchStr: str,pageNumber: int,resultsPerPage: int,actor: str) -> str:
"""Search results for shared items """Search results for shared items
""" """