Skip to content

Commit 53f8f20

Browse files
committed
Tidy up
Now does all the data gathering in the loop and prints out results from the in memory structure rather than during the loop.
1 parent 73b929c commit 53f8f20

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

bart.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
stations = dom.getElementsByTagName('stations')[0]
1010
stationData = {}
1111

12+
print 'Begin reading data from SF BART API, please wait!'
13+
1214
for station in stations.getElementsByTagName('station'):
1315
stationAbbr = station.getElementsByTagName('abbr')[0].firstChild.nodeValue
1416

@@ -19,14 +21,12 @@
1921
dom = parseString(data)
2022

2123
stationName = dom.getElementsByTagName('name')[0].firstChild.nodeValue
22-
print '********** DEPARTURES FROM {stationName} **********'.format(stationName = stationName)
2324

2425
stationEtds = dom.getElementsByTagName('etd')
2526
stationDestinations = {}
2627

2728
for etd in stationEtds:
2829
destination = etd.getElementsByTagName('destination')[0].firstChild.nodeValue
29-
print 'Destination: {destination}'.format(destination = destination)
3030

3131
stationDestinationDepartures = []
3232

@@ -39,7 +39,6 @@
3939
platform = estimate.getElementsByTagName('platform')[0].firstChild.nodeValue
4040
numCars = estimate.getElementsByTagName('length')[0].firstChild.nodeValue
4141
lineColor = estimate.getElementsByTagName('color')[0].firstChild.nodeValue
42-
print '- {numCars} car {lineColor} line train leaves in {minutesToDeparture} minutes from platform {platform}.'.format(numCars = numCars, lineColor = lineColor, minutesToDeparture = minutesToDeparture, platform = platform)
4342

4443
stationDestinationDeparture['platform'] = platform
4544
stationDestinationDeparture['numCars'] = numCars
@@ -50,5 +49,19 @@
5049

5150
stationDestinations[destination] = stationDestinationDepartures
5251

53-
stationData[stationAbbr] = stationDestinations
52+
stationData[stationName] = stationDestinations
53+
54+
print 'Done reading data from SF BART API'
55+
print ''
56+
57+
for stationName in stationData.keys():
58+
stationDestinations = stationData[stationName]
59+
print '********** DEPARTURES FROM {stationName} **********'.format(stationName= stationName)
60+
61+
for stationDestination in stationDestinations.keys():
62+
print stationDestination
63+
64+
for departure in stationDestinations[stationDestination]:
65+
print '- {numCars} car {lineColor} line train leaves in {minutesToDeparture} minutes from platform {platform}.'.format(numCars = departure['numCars'], lineColor = departure['lineColor'], minutesToDeparture = departure['minutesToDeparture'], platform = departure['platform'])
66+
5467

0 commit comments

Comments
 (0)