diff --git a/functions.py b/functions.py index aa259e1..53f453b 100644 --- a/functions.py +++ b/functions.py @@ -277,11 +277,18 @@ EMOJI_BASE_PATH = Path.cwd() / 'static' / 'emojis' emoji_cache = {} +def to_snake_case(name): + name = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name) + return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', name).lower() + def find_emoji_path(emoji_name): - head, sep, tail = emoji_name.partition('_') + if '_' in emoji_name: + head, sep, tail = emoji_name.partition('_') + else: + head = to_snake_case(emoji_name).split('_')[0] if any(Path(EMOJI_BASE_PATH).glob(f'{head}.json')): for json_file in Path(EMOJI_BASE_PATH).glob('*.json'): - print("\n[CatAsk/functions/find_emoji_path] Using JSON meta file\n") + app.logger.debug("\n[CatAsk/functions/find_emoji_path] Using JSON meta file\n") pack_data = loadJSON(json_file) emojis = pack_data.get('emojis', [])