Skip to content

Instantly share code, notes, and snippets.

@AutonomousCat
Last active July 15, 2023 14:42
Show Gist options
  • Save AutonomousCat/8f4274fd4b858c5a1499057e2ed142ce to your computer and use it in GitHub Desktop.
Save AutonomousCat/8f4274fd4b858c5a1499057e2ed142ce to your computer and use it in GitHub Desktop.
Twemoji Codepoint -> Name Converter ~ Run in twemoji folder, which you should clone from: https://github.com/twitter/twemoji
import os
import shutil
import emoji
import time
CONVERTED_DIR = 'name_converted'
SOURCE_DIR = 'assets/svg'
class EmojiRenamer:
def __init__(self):
self.dest_dir = os.path.join(CONVERTED_DIR, (str(int(time.time()))))
os.makedirs(self.dest_dir, exist_ok=True)
self.unicode_dict = emoji.unicode_codes.EMOJI_DATA
self.rename_files()
def get_emoji_name(self, codepoints):
name = None
codepoints = ''.join([chr(int(codepoint, 16)) for codepoint in codepoints.split('-')])
if codepoints in self.unicode_dict:
name = self.unicode_dict[codepoints]['en']
invalid_chars = ':-*'
for char in invalid_chars:
name = name.replace(char, '_')
name = name.lower().strip('_')
return name
def rename_files(self):
for filename in os.listdir(SOURCE_DIR):
basename, ext = os.path.splitext(filename)
name = self.get_emoji_name(basename)
if name:
new_filename = name + ext
new_filepath = os.path.join(self.dest_dir, new_filename)
shutil.copy(os.path.join(SOURCE_DIR, filename), new_filepath)
EmojiRenamer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment