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