Skip to content

Commit

Permalink
Pull the emoji list from unicode.org (#612)
Browse files Browse the repository at this point in the history
- Removing unused information (names and descriptions) from the Emoji class
- Creating a Gradle task that generates a more efficient res/raw/emojis.txt file from the most recent Unicode standard
- Saving recently used emoji preferences as emoji values rather than names
- Migrating old user preferences to the new system
  • Loading branch information
tmqCypher authored May 8, 2024
1 parent 53e04d5 commit a91332a
Show file tree
Hide file tree
Showing 6 changed files with 4,621 additions and 3,860 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ tasks.register('buildKeyboardFont') {
}
}

tasks.register('genEmojis') {
println "\nGenerating res/raw/emojis.txt"
exec {
workingDir = projectDir
commandLine "python", "gen_emoji.py"
}
}

tasks.withType(Test).configureEach {
dependsOn 'genLayoutsList'
dependsOn 'checkKeyboardLayouts'
Expand Down
38 changes: 38 additions & 0 deletions gen_emoji.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import urllib.request
import os.path

EMOJIS_PATH = 'res/raw/emojis.txt'
EMOJI_TEST_PATH = 'emoji-test.txt'
EMOJI_TEST_URL = 'https://unicode.org/Public/emoji/latest/emoji-test.txt'

def rawEmojiFromCodes(codes):
return ''.join([chr(int(c, 16)) for c in codes])

def getEmojiTestContents():
if os.path.exists(EMOJI_TEST_PATH):
print(f'Using existing {EMOJI_TEST_PATH}')
else:
print(f'Downloading {EMOJI_TEST_URL}')
urllib.request.urlretrieve(EMOJI_TEST_URL, EMOJI_TEST_PATH)
return open(EMOJI_TEST_PATH, mode='r', encoding='UTF-8').read()


emoji_list = []
group_indices = []
for line in getEmojiTestContents().splitlines():
if line.startswith('# group:'):
if len(group_indices) == 0 or len(emoji_list) > group_indices[-1]:
group_indices.append(len(emoji_list))
elif not line.startswith('#') and 'fully-qualified' in line:
codes = line.split(';')[0].split()
emoji_list.append(rawEmojiFromCodes(codes))

with open(EMOJIS_PATH, 'w', encoding='UTF-8') as emojis:
for e in emoji_list:
emojis.write(f'{e}\n')
emojis.write('\n')

emojis.write(' '.join([str(g) for g in group_indices]))
emojis.write('\n')

print(f'Parsed {len(emoji_list)} emojis in {len(group_indices)}')
Loading

0 comments on commit a91332a

Please sign in to comment.