-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hexcode compatible with OpenMoji #190
Comments
Does that mean you would like to replace a I wonder if we should hardcode the hex codes in the EMOJI_DATA dict. They are very easy to generate on runtime with your function, so maybe generating them on runtime makes more sense. |
That's what I mean. |
I created a script to test it: main.pyprint("############## main.py ###############")
import emoji
import requests
import html
def hexcode(emoji):
# rjust(4, '0') is necessary to convert "2A" to "002A"
codes = [hex(ord(e))[2:].upper().rjust(4, '0') for e in emoji]
return "-".join(codes)
# Try to match all emoji from EMOJI_DATA to Openmoji:
openmoji = requests.get("https://github.com/hfg-gmuend/openmoji/raw/master/data/openmoji.json").json()
hexToOpenmoji = {value["hexcode"]: value for value in openmoji}
emojiToOpenmoji = {}
print("Following emoji couldn't be found in Openmoji:")
for emj in emoji.EMOJI_DATA:
found = False
if hexcode(emj) in hexToOpenmoji:
emojiToOpenmoji[emj] = hexToOpenmoji[hexcode(emj)]
found = True
elif emj[-1] == '\ufe0f':
# Remove the emoji variant u+fe0f and try again
emj_no_variant = emj[0:-1]
if hexcode(emj_no_variant) in hexToOpenmoji:
emojiToOpenmoji[emj] = hexToOpenmoji[hexcode(emj_no_variant)]
found = True
else:
# Append the emoji variant u+fe0f and try again
emj_emoji_variant = emj + '\ufe0f'
if hexcode(emj_emoji_variant) in hexToOpenmoji:
emojiToOpenmoji[emj] = hexToOpenmoji[hexcode(emj_emoji_variant)]
found = True
if not found and emoji.EMOJI_DATA[emj]['status'] == emoji.STATUS['fully_qualified']:
print(f"E{emoji.EMOJI_DATA[emj]['E']} {emoji.EMOJI_DATA[emj]['en']} {hexcode(emj)} {emj}")
print("###########################")
def replace_fct(emj, emj_data):
if emj in emojiToOpenmoji:
alt = html.escape(emj)
title = html.escape(emj_data['en'])
src = html.escape(emojiToOpenmoji[emj]["hexcode"]) + ".svg"
return f'<img src="{src}" alt="{alt}" title="{title}">'
else:
return "Unsupported emoji"
print(emoji.emojize("a lion in html: :lion:", version=-1, handle_version=replace_fct)) For some emoji it is necessary to remove the variant indicator |
Can we add hexcode to
emoji.EMOJI_DATA
?https://github.com/hfg-gmuend/openmoji are indentied by their hexcode.
I use the emoji package in production for Subreply. I intend to add OpenMoji as soon as they are production ready.
The text was updated successfully, but these errors were encountered: