-
Notifications
You must be signed in to change notification settings - Fork 2
/
locations.py
36 lines (27 loc) · 1.1 KB
/
locations.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
import json
class Location:
def __init__(self, crs, tiploc, name, toc):
self.crs = crs
self.tiploc = tiploc
self.name = name
self.toc = toc
def __str__(self):
return "{} - {} - {} - {}".format(self.crs, self.tiploc, self.toc, self.name)
def __repr__(self):
return self.__str__()
class LocationMapper:
def __init__(self, locations_file_path):
with open(locations_file_path) as f:
locations = json.loads(f.read())
self.location_map = {}
for l in locations["locations"]:
if "tiploc" in l and "crs" in l and "toc" in l and "name" in l:
nl = Location(l["crs"], l["tiploc"], l["name"], l["toc"])
self.location_map[nl.tiploc] = nl
def get_crs(self, tiploc):
return self.location_map[tiploc].crs
def get_name(self, tiploc):
return self.location_map[tiploc].name
if __name__ == "__main__":
lm = LocationMapper("../national-rail-stations/stations.json")
print("PLYMTH -> {} [{}].".format(lm.get_crs("PLYMTH"), lm.get_name("PLYMTH")))