53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import requests
|
||
|
import json
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
in_data = requests.get("https://github.com/mattermost/mattermost-webapp/raw/master/utils/emoji.json").json()
|
||
|
"""
|
||
|
{
|
||
|
"name": "GRINNING FACE",
|
||
|
"unified": "1F600",
|
||
|
"short_name": "grinning",
|
||
|
"short_names": [
|
||
|
"grinning"
|
||
|
],
|
||
|
"text": ":D",
|
||
|
"texts": null,
|
||
|
"category": "smileys-emotion"
|
||
|
},
|
||
|
"""
|
||
|
|
||
|
|
||
|
def text_or_emoji(emoji_entry):
|
||
|
if emoji_entry.get("text") and emoji_entry.get("short_name") != "blush":
|
||
|
return emoji_entry["text"]
|
||
|
elif emoji_entry.get("unified"):
|
||
|
textual_unicode = emoji_entry["unified"]
|
||
|
assert re.fullmatch("[0-9A-F]{4,5}(-[0-9A-F]{4,5})*", textual_unicode)
|
||
|
return "".join(
|
||
|
chr(int(c, base=16)) for c in textual_unicode.split("-")
|
||
|
)
|
||
|
else:
|
||
|
return None
|
||
|
|
||
|
|
||
|
out_data = {
|
||
|
short_name: text_or_emoji(emoji_entry)
|
||
|
for emoji_entry in in_data
|
||
|
for short_name in emoji_entry["short_names"]
|
||
|
}
|
||
|
out_data = {k: v for k, v in out_data.items() if v is not None}
|
||
|
|
||
|
out = json.dumps(out_data, ensure_ascii=False)
|
||
|
out = re.sub(", *", ",\n", out)
|
||
|
|
||
|
print(f"""// The rest of this file uses data provided by Mattermost.
|
||
|
// In sofar as it is protectable by copyright, it is licensed under the Apache license:
|
||
|
// https://github.com/mattermost/mattermost-webapp/blob/51185f6969bed6d061558de65f0722ffb6dc62b3/LICENSE.txt
|
||
|
//
|
||
|
// Generated with /tools/update_emoji.py
|
||
|
const emoji = {out};""")
|