Skip to content

Instantly share code, notes, and snippets.

@amane-katagiri
Last active August 9, 2017 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amane-katagiri/687654c0dc00736aba69235e27025d4e to your computer and use it in GitHub Desktop.
Save amane-katagiri/687654c0dc00736aba69235e27025d4e to your computer and use it in GitHub Desktop.
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