Skip to content

Instantly share code, notes, and snippets.

@ewerybody
Created March 12, 2021 12:08
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 ewerybody/7c6bac0eeb3160daaad6d913e9ce040f to your computer and use it in GitHub Desktop.
Save ewerybody/7c6bac0eeb3160daaad6d913e9ce040f to your computer and use it in GitHub Desktop.
find emojis under 100000/hex 186A0
#py3 - find emojis under 100000/hex 186A0
import os
MAX_NR = 100000
URL = 'https://unicode.org/Public/emoji/13.1/emoji-test.txt'
TXT_NAME = 'emoji-test.txt'
TXT_PATH = os.path.abspath(os.path.join(__file__, '..', TXT_NAME))
emojis = {}
content = ''
if os.path.isfile(TXT_PATH):
with open(TXT_PATH, encoding='utf8') as fob:
content = fob.read()
else:
import urllib.request
content = urllib.request.urlopen(URL).read().decode()
for line in content.split('\n'):
if line.startswith('#'):
continue
if not line.strip():
continue
# get number blocks and description
nrs_str, line_end = line.split(';', 1)
nrs = nrs_str.strip().split()
# skip ones with multiple nr blocks
if len(nrs) > 1:
continue
# convert from hex
nr = int(nrs[0], 16)
if nr < MAX_NR:
emojis[nr] = line_end.rsplit('#')[1].strip()
for nr, txt in sorted(emojis.items()):
print('&&#35;%i; : %s' % (nr, txt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment