-
Notifications
You must be signed in to change notification settings - Fork 0
/
tzdump.py
executable file
·44 lines (37 loc) · 1.11 KB
/
tzdump.py
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
42
43
44
#!/usr/bin/env python3
import sys
import csv
from typing import List
filename = "/usr/share/zoneinfo/tzdata.zi"
if len(sys.argv) == 2:
filename = sys.argv[1]
def tzdata_filter(line: str) -> bool:
"""Filter tzdata.zi file for zones"""
if line and line[0] == 'Z' :
return True
return False
timezones : List[str] = []
with open(filename) as zonetab:
reader = csv.reader(filter(tzdata_filter, zonetab), delimiter=' ')
for row in reader:
timezones.append(row[1])
print('package main')
print()
print('// auto-generated by tzdump.py. DO NOT EDIT')
print()
print('// Timezones is a list of available timezones')
print('var Timezones = []string{')
for tz in timezones:
print('\t"{}",'.format(tz))
print('}')
print()
# Prepare array with cities/locations only for fuzzy matching
print('// Locations is a list of locations without continent/ocean for fuzzy matching')
print('// index in Locations must match index in Timezones')
print('var Locations = []string{')
for tz in timezones:
x = tz.split('/')
loc = x[-1]
loc = loc.replace('_', ' ')
print('\t"{}",'.format(loc))
print('}')