FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
update-windows-zones.py
1#!/usr/bin/env python3
2
3import os
4import urllib.request
5import xml.etree.ElementTree as ET
6
7name = os.path.realpath(__file__)
8base = os.path.normpath(os.path.join(os.path.dirname(name), '..'))
9rname = os.path.relpath(name, base)
10zfile = os.path.join(base, 'winpr/libwinpr/timezone/WindowsZones.c')
11#url = 'https://raw.githubusercontent.com/unicode-org/cldr/latest/common/supplemental/windowsZones.xml'
12url = 'https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml'
13
14try:
15 with urllib.request.urlopen(url) as response:
16 xml = response.read()
17 root = ET.fromstring(xml)
18 entries = []
19 for child in root.iter('mapZone'):
20 tzid = child.get('type')
21 windows = child.get('other')
22 entries += ['\t{ "' + windows + '", "' + tzid + '" },\n']
23 entries.sort()
24
25 with open(zfile, 'w') as f:
26 f.write('/*\n')
27 f.write(' * Automatically generated with ' + str(rname) + '\n')
28 f.write(' */\n')
29 f.write('\n')
30 f.write('#include "WindowsZones.h"\n')
31 f.write('\n')
32 f.write('const WINDOWS_TZID_ENTRY WindowsTimeZoneIdTable[] =\n')
33 f.write('{\n')
34 for entry in entries:
35 f.write(entry)
36 f.write('};\n')
37 f.write('\n');
38 f.write('const size_t WindowsTimeZoneIdTableNrElements = ARRAYSIZE(WindowsTimeZoneIdTable);\n')
39except Exception as e:
40 print('----------------------------------------------------')
41 print(str(e))
42 print('----------------------------------------------------')