Created
March 9, 2020 15:18
-
-
Save alvations/a55679184ffd3f74bf4360079c4e93b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from io import StringIO | |
response = requests.get('https://unicode.org/Public/emoji/13.0/emoji-sequences.txt') | |
with open('emoji.txt', 'w') as fout: | |
with StringIO(response.content.decode('utf8')) as fin: | |
for line in fin: | |
if line.strip() and not line.startswith('#'): | |
hexa = line.split(';')[0].split('..') | |
if len(hexa) == 1: # One codepoint for this emoji | |
# It's possible that one codepoint has >=1 hexadecimal. | |
ch = ''.join([chr(int(h, 16)) for h in hexa[0].strip().split(' ')]) | |
print(ch, end='\n', file=fout) | |
else: # Multiple codepoint for this emoji | |
start, end = hexa | |
for ch in range(int(start, 16), int(end, 16)+1): | |
# Assume that only one hexadecimal per codepoint. | |
print(ch, end='\n', file=fout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment