-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpl-to-csv.py
executable file
·45 lines (40 loc) · 1.25 KB
/
fpl-to-csv.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
45
#!/usr/bin/env python3
import sys
import xml.etree.ElementTree as ET
def main():
try:
tree = ET.parse(sys.argv[1])
except:
print(f"Usage:\n {sys.argv[0]} filename.fpl [WAYPOINT_PREFIX]")
sys.exit(1)
root = tree.getroot()
if root.tag.endswith("flight-plan"):
namespace = root.tag[root.tag.index("{"):root.tag.index("}")+1]
print(f"Namespace: {namespace}")
print(f"Got {root.tag}")
else:
print(f"Unknown tree: {root.tag}")
sys.exit(1)
wprefix = None
if len(sys.argv) > 2:
wprefix = sys.argv[2]
for child in root:
if child.tag.endswith("waypoint-table"):
ofilename = f"{sys.argv[1]}.csv"
print("Found waypoint-table")
print(f"Writing {ofilename}")
with open(ofilename, "w") as ofile:
for waypoint in child:
if waypoint.find(namespace+"type").text == "USER WAYPOINT":
name = waypoint.find(namespace+"identifier").text
if wprefix:
name = wprefix + name[2:]
lat = waypoint.find(namespace+"lat").text
lon = waypoint.find(namespace+"lon").text
ofile.write(f"{name.upper()},,{lat},{lon}\r\n")
print("Done.")
break
else:
print("No waypoint-table found.")
if __name__ == "__main__":
main()