Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Emoji list generator for https://github.com/kernc/mdx_unimoji.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
Generate emoji list json file for mdx_unimoji(https://github.com/kernc/mdx_unimoji).
You can convert emoji_strategy.json on emojione (https://github.com/emojione/emojione) into
`{"ENTITY1": ["NAME1"], "ENTITY2": ["NAME2", "ALTERNAME2", ...], ...}`.
Usage:
$ ./emoji_generator.py https://raw.githubusercontent.com/Ranks/emojione/master/emoji_strategy.json
Run emoji_generator.py with no parameter to pass json data from stdin.
$ curl https://raw.githubusercontent.com/Ranks/emojione/master/emoji_strategy.json | \
./emoji_generator.py > emoji.json
"""
import json
import sys
from urllib.request import urlopen
def main(text):
"""Generate emoji table function."""
emojson = json.loads(text)
emojis = dict()
for x in emojson.values():
code = "".join([chr(int(c, base=16)) for c in x["unicode_output"].split("-")])
emojis[code] = [x["shortname"]] + x["shortname_alternates"]
return emojis
if __name__ == "__main__":
if len(sys.argv) > 1:
text = urlopen(sys.argv[1]).read().decode("utf-8")
else:
text = input()
print(json.dumps(main(text)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.