-
Notifications
You must be signed in to change notification settings - Fork 1
/
Line.py
38 lines (27 loc) · 1.05 KB
/
Line.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
import string
class Line:
# the name of the line; for example, '1'
id = None
# a dictionary of Direction objects describing directions for this line
directions = None
# a dictionary of active buses on this line
buses = None
def __init__(self, id=None, directions=None, buses=None):
self.id = id
self.directions = directions if directions is not None else {}
self.buses = buses if buses is not None else {}
def __str__(self):
output = "Line: %s\n" \
"Directions: %s\n" % (self.id, string.join(self.directions.keys(), ', '))
for direction, data in self.directions.iteritems():
output += "%s\n" % data
return output
def addDirection(self, direction):
self.directions[direction.id] = direction
def getAvailableDirections(self):
return self.directions.keys()
def getStopsFor(self, sDirection):
if sDirection not in self.directions:
return KeyError
else:
return self.directions[sDirection].stops