started with caching classes
[pywienerlinien] / gotovienna / elements.py
1 from realtime import ITipParser
2
3 class Line:
4     def __init__(self, name):
5         self._stations = None
6         self.parser = ITipParser()
7         if name.strip() in self.parser.lines():
8             self.name = name.strip()
9         else:
10             raise LineNotFoundError('There is no line "%s"' % name.strip())
11
12     @property
13     def stations(self):
14         if not self._stations:
15             self._stations = parser.get_stations(self.name)
16         return self._stations
17
18     def get_departures(self, stationname):
19         stationname = stationname.strip().lower()
20         stations = self.stations
21
22         found = false
23
24         for direction in stations.keys():
25             # filter stations starting with stationname
26             stations[direction] = filter(lambda station: station[0].lower().starts_with(stationname), stations)
27             found = found or bool(stations[direction])
28
29         if found:
30             # TODO return departures
31             raise NotImplementedError()
32         else:
33             raise StationNotFoundError('There is no stationname called "%s" at route of line "%s"' % (stationname, self.name))
34
35 class Station:
36     def __init__(self):
37         pass