Created
March 25, 2015 17:20
-
-
Save werdnum/513e85f94754362a655f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import csv | |
import json | |
import re | |
import requests | |
data = {} | |
def append_data(name, newData, source): | |
if not name in data: | |
data[name] = { | |
'name': name, | |
'semantics': None, | |
'unicode': None, | |
'file': None, | |
'sources': [], | |
'variants': [] | |
} | |
data[name].update(newData) | |
data[name]['sources'].append(source) | |
with open('images.json') as f: | |
ooUiData = json.load(f) | |
for (iconPack, packData) in ooUiData['images'].items(): | |
if not re.match('^icons($|-)', iconPack): | |
continue | |
for (iconName, iconData) in packData.items(): | |
thisIcon = {} | |
thisIcon['file'] = iconData['file'] | |
thisIcon['oojs-ui-pack'] = iconPack | |
if 'variants' in iconData: | |
thisIcon['variants'] = iconData['variants'] | |
else: | |
thisIcon['variants'] = [] | |
append_data(iconName, thisIcon, 'ooui') | |
with open('wikifont-icons.tsv', 'rb') as f: | |
csvReader = csv.DictReader(f, dialect='excel-tab') | |
for row in csvReader: | |
name_parts = row['Icon name'].split(' - ') | |
if len(name_parts) != 2: | |
continue | |
prefixed_codepoint, filename = name_parts | |
iconName = re.sub('\.svg$', '', filename) | |
thisIcon = { | |
'semantics': row['Usages'], | |
'unicode': re.sub('^uni', '', prefixed_codepoint), | |
} | |
append_data(iconName, thisIcon, 'wikifont') | |
print json.dumps(data, sort_keys=True, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment