-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (47 loc) · 1.67 KB
/
main.py
File metadata and controls
55 lines (47 loc) · 1.67 KB
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
45
46
47
48
49
50
51
52
53
54
55
from xml.dom.minidom import parse
# Load calendar file from URL
# Save file to path
# .env file for download URL
# .env file for upload path
# https://stackoverflow.com/questions/68335/how-to-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh
file_in = open('calendar.vcal', 'r')
file_out = open('calendar_out.vcal', 'w')
count = 0
TZCOLON = "TZID:"
TZEQUALS = "TZID="
def loadTimeZoneData():
# File from here https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml
# https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml
timezones = dict()
with parse("windowsZones.xml") as dom:
for zone in dom.getElementsByTagName("mapZone"):
if zone.getAttribute("territory") == "001":
timezones[zone.getAttribute("other")]= zone.getAttribute("type")
return timezones
def getTimeZone(line):
if TZCOLON in line:
start = line.find(TZCOLON)
currentTimeZone = line[start + len(TZCOLON):]
return currentTimeZone
elif TZEQUALS in line:
start = line.find(TZEQUALS)
end = line.find(":", start + len(TZEQUALS))
currentTimeZone = line[start + len(TZEQUALS):end]
return currentTimeZone
else:
print("Error: Could not process line:")
return None
timezones = loadTimeZoneData()
print(len(timezones))
while True:
count += 1
line = file_in.readline()
if not line:
break
if "TZID" in line:
timezone = getTimeZone(line.strip())
iana_timezone = timezones[timezone]
line = line.replace(timezone, iana_timezone)
file_out.writelines(line)
file_in.close()
file_out.close()