import argparse import json import logging import os logging.basicConfig() logger = logging.getLogger() def setup_logging_level(debug=False): log_level = logging.DEBUG if debug else logging.ERROR logger.setLevel(log_level) logger.debug("Debugging enabled") def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('query', nargs='*', default="", help="freeform") parser.add_argument('--debug', dest='debug', action='store_true') return parser.parse_args() maindir = os.path.join('data', 'emojis') def process_file(json_filename, txt_filename): with open(json_filename) as jf: j = json.load(jf) shortcuts = j['abbreviation']['abbreviations'] with open(txt_filename) as tf: text = tf.read() unicode_point = text.split('+u')[1].split('')[0] c = '\\u{}'.format(unicode_point) with open(os.path.join('data', 'emoji.json')) as f: j = json.load(f) for emoji in j: try: this_codepoint = hex(ord(emoji['emoji']))[2:] except: continue if this_codepoint == unicode_point: print("{} - {} - {}".format(c, emoji['emoji'], shortcuts)) def main(): args = parse_args() setup_logging_level(args.debug) for d, sub, files in os.walk(maindir): for file in files: if file.endswith('.json'): json_filename = os.path.join(d, file) txt_filename = os.path.join(d, file[1:].split('.json')[0] + '.txt') process_file(json_filename, txt_filename) if __name__ == "__main__": main()