-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
61 lines (46 loc) · 2.22 KB
/
parser.py
File metadata and controls
61 lines (46 loc) · 2.22 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
56
57
58
59
60
61
# returns the location and path coords by parsing the file
def ParseFile(filePath):
locationMarkerCoords = []
PathMarkerCoords = []
locationMarkerNames = []
with open(filePath, "r") as file:
lines = file.readlines()
# i is the index of the line
for i, line in enumerate(lines):
if line.startswith("--"):
continue
if line.startswith("Location:"):
# check if next line exists
if i + 1 < len(lines):
coordsLine = lines[i + 1].strip()
[coords, name] = coordsLine.split("#")
coords = coords.strip()
name = name.strip()
coords = coords.removeprefix("(").strip().removesuffix(")")
# print(coordsLine)
#convert the integers into a tuple
coord = tuple(map(int, coords.split(", ")))
locationMarkerCoords.append(coord)
locationMarkerNames.append(name)
if line.startswith("Path"):
pathCoords = []
# check if next line exists
if i + 1 < len(lines):
coordsLine = lines[i + 1].strip()
coordsLine = coordsLine.removeprefix("(").removesuffix(")").strip()
# print(coordsLine)
#convert the integers into a tuple
coord = tuple(map(int, coordsLine.split(", ")))
pathCoords.append(coord)
# continue adding the next line until it is not a coordinate
c = i + 2
while c < len(lines) and lines[c].startswith("("):
coordsLine = lines[c].strip()
coordsLine = coordsLine.removeprefix("(").removesuffix(")").strip()
# print(coordsLine)
#convert the integers into a tuple
coord = tuple(map(int, coordsLine.split(", ")))
pathCoords.append(coord)
c += 1
PathMarkerCoords.append(pathCoords)
return locationMarkerCoords, locationMarkerNames, PathMarkerCoords