# This script generates the mapping between MS Windows timezone names and
# Olsen timezone names, by retrieving a file:
# http://unicode.org/cldr/data/common/supplemental/supplementalData.xml
# and parsing it, and from this generating the file windows_tz.py.

XML_SOURCE = 'http://unicode.org/cldr/data/common/supplemental/windowsZones.xml'
import urllib
from xml.dom import minidom
from pprint import pprint

source = urllib.urlopen(XML_SOURCE)
dom = minidom.parse(source)

for element in dom.getElementsByTagName('mapTimezones'):
    if element.getAttribute('type') == u'windows':
        break

mappings = {}
for mapping in element.getElementsByTagName('mapZone'):
    mappings[mapping.getAttribute('other')] = mapping.getAttribute('type').split(' ')[0]
    

source.close()
with open('tzlocal/windows_tz.py', "w") as out:
    out.write("# This file is autogenerated by the get_windows_info.py script\n"
              "# Do not edit.\ntz_names = ")
    pprint(mappings, out)
