FreeRDP
update-windows-zones.py
1 #!/usr/bin/env python3
2 
3 import os
4 import urllib.request
5 import xml.etree.ElementTree as ET
6 
7 name = os.path.realpath(__file__)
8 base = os.path.normpath(os.path.join(os.path.dirname(name), '..'))
9 rname = os.path.relpath(name, base)
10 zfile = os.path.join(base, 'winpr/libwinpr/timezone/WindowsZones.c')
11 #url = 'https://raw.githubusercontent.com/unicode-org/cldr/latest/common/supplemental/windowsZones.xml'
12 url = 'https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml'
13 
14 try:
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')
39 except Exception as e:
40  print('----------------------------------------------------')
41  print(str(e))
42  print('----------------------------------------------------')