Created
March 3, 2012 23:13
-
-
Save tomer/1968859 to your computer and use it in GitHub Desktop.
Convert CLDR zones into Mediawiki markup
This file contains hidden or 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
import xml.dom.minidom | |
import os.path | |
import urllib2 | |
def getText(item): | |
return " ".join(t.nodeValue for t in item.childNodes if t.nodeType == t.TEXT_NODE) | |
def get_file(filename, url): | |
f = urllib2.urlopen(url) | |
output = open(filename,'wb') | |
output.write(f.read()) | |
output.close() | |
def get_file_if_missing(filename, url): | |
if not os.path.isfile(filename): | |
print ("Downloading data file. Please wait...") | |
get_file(filename, url) | |
def save_file(filename, content): | |
f = open(filename, 'w') | |
f.write(content) | |
f.close() | |
def sort_dict(adict): | |
keys = adict.keys() | |
keys.sort() | |
return map(adict.get, keys) | |
################### | |
get_file_if_missing('he.xml', 'http://unicode.org/cldr/trac/browser/tags/release-21/common/main/he.xml?format=txt') | |
dom = xml.dom.minidom.parse ("he.xml") | |
tz = dom.getElementsByTagName("timeZoneNames")[0] | |
zones = tz.getElementsByTagName("zone") | |
list = dict() | |
for zone in zones: | |
item = dict() | |
item['type'] = zone.getAttribute('type') | |
item['value'] = getText(zone.getElementsByTagName('exemplarCity')[0]) | |
list[item['type']] = item | |
list = sort_dict(list) | |
print "{| " | |
for item in list: | |
print "|", | |
for word in item['type'].split("/"): | |
print u"{:^30} ||".format(u"[[:en:{0}|{1}]]".format(word,word)), | |
for word in item['value'].split("/"): | |
print u"{:^30} ||".format(u"[[{0}]]".format(word)), | |
print "|{:-^102}".format("") | |
print "|}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment