Lookup emoji codes from their names for the common emoji list

main
Bob Mottram 2022-04-19 15:18:54 +01:00
parent 77cd289a5e
commit a7cb0ead44
1 changed files with 17 additions and 0 deletions

View File

@ -1677,6 +1677,11 @@ def set_custom_background(base_dir: str, background: str,
def html_common_emoji(base_dir: str, no_of_emoji: int) -> str:
"""Shows common emoji
"""
emojis_filename = base_dir + '/emoji/emoji.json'
if not os.path.isfile(emojis_filename):
emojis_filename = base_dir + '/emoji/default_emoji.json'
emojis_json = None
common_emoji_filename = base_dir + '/accounts/common_emoji.txt'
if not os.path.isfile(common_emoji_filename):
return ''
@ -1695,6 +1700,18 @@ def html_common_emoji(base_dir: str, no_of_emoji: int) -> str:
while ctr < no_of_emoji and line_ctr < len(common_emoji):
emoji_name = common_emoji[line_ctr].split(' ')[1].replace('\n', '')
emoji_filename = base_dir + '/emoji/' + emoji_name + '.png'
if not os.path.isfile(emoji_filename):
# load the emojis index
if not emojis_json:
emojis_json = load_json(emojis_filename)
# lookup the name within the index to get the hex code
if emojis_json:
for emoji_tag, emoji_code in emojis_json.items():
if emoji_tag == emoji_name:
emoji_name = emoji_code
# get the filename based on the hex code
emoji_filename = \
base_dir + '/emoji/' + emoji_name + '.png'
if os.path.isfile(emoji_filename):
# NOTE: deliberately no alt text, so that without graphics only
# the emoji name shows