Blame files/emoji_clean_json.py

Neal Gompa f59afc
#!/usr/bin/env python
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon 67d1cc
from __future__ import print_function, absolute_import
Pierre-Yves Chibon d8e06b
import json
Pierre-Yves Chibon d8e06b
import os
Pierre-Yves Chibon d8e06b
import sys
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
data = None
Pierre-Yves Chibon d8e06b
with open('emoji_strategy.json') as stream:
Pierre-Yves Chibon d8e06b
    data = json.load(stream)
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
if not data:
Vadim Rutkovsky 9b6a62
    print('Could not load the data from the JSON file')
Pierre-Yves Chibon d8e06b
    sys.exit(1)
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
# Retrieve the items we keep in the JSON
Pierre-Yves Chibon d8e06b
tokeep = {}
Pierre-Yves Chibon d8e06b
for key in data:
Pierre-Yves Chibon d8e06b
    if '-' in data[key]['unicode'] and data[key]['unicode'].startswith('1F'):
Pierre-Yves Chibon d8e06b
        continue
Pierre-Yves Chibon d8e06b
    tokeep[key] = data[key]
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
# Check if we have the keys of all images we kept
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
unicodes = [tokeep[key]['unicode'] for key in tokeep]
Pierre-Yves Chibon d8e06b
images = [item.replace('.png', '') for item in os.listdir('png')]
Pierre-Yves Chibon d8e06b
Vadim Rutkovsky 9b6a62
print(set(unicodes).symmetric_difference(set(images)))
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
Pierre-Yves Chibon d8e06b
with open('emoji_strategy2.json', 'w') as stream:
Pierre-Yves Chibon d8e06b
    json.dump(tokeep, stream)