import os
import subprocess
import unicodedata


def main():
    with open('emoji-data.txt') as f:
        for ln in f:
            u = ln.split('#')[0].split(';')[0].strip()
            if not u:
                continue
            print('#', u)
            if '..' in u:
                start, end = u.split('..')
                for x in range(int(start, 16),
                               int(end, 16) + 1):
                    code_point(x)
            else:
                code_point(int(u, 16))


def code_point(n):
    try:
        name = unicodedata.name(chr(n))
    except:
        name = 'unknown'
    filename = '{0}_-_{1}'.format(hex(n)[2:],
                                  '_'.join(name.lower().split()))
    print(filename)
    path = os.path.join('sprites', filename)
    tgt = os.path.join(path, 'sprite.ase')
    if not os.path.exists(path):
        os.makedirs(os.path.join('sprites', filename))
    if not os.path.exists(tgt):
        subprocess.check_output(['cp', 'blank.ase', tgt])

if __name__ == '__main__':
    main()
