|
9 | 9 | stations = dom.getElementsByTagName('stations')[0] |
10 | 10 | stationData = {} |
11 | 11 |
|
| 12 | +print 'Begin reading data from SF BART API, please wait!' |
| 13 | + |
12 | 14 | for station in stations.getElementsByTagName('station'): |
13 | 15 | stationAbbr = station.getElementsByTagName('abbr')[0].firstChild.nodeValue |
14 | 16 |
|
|
19 | 21 | dom = parseString(data) |
20 | 22 |
|
21 | 23 | stationName = dom.getElementsByTagName('name')[0].firstChild.nodeValue |
22 | | - print '********** DEPARTURES FROM {stationName} **********'.format(stationName = stationName) |
23 | 24 |
|
24 | 25 | stationEtds = dom.getElementsByTagName('etd') |
25 | 26 | stationDestinations = {} |
26 | 27 |
|
27 | 28 | for etd in stationEtds: |
28 | 29 | destination = etd.getElementsByTagName('destination')[0].firstChild.nodeValue |
29 | | - print 'Destination: {destination}'.format(destination = destination) |
30 | 30 |
|
31 | 31 | stationDestinationDepartures = [] |
32 | 32 |
|
|
39 | 39 | platform = estimate.getElementsByTagName('platform')[0].firstChild.nodeValue |
40 | 40 | numCars = estimate.getElementsByTagName('length')[0].firstChild.nodeValue |
41 | 41 | 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) |
43 | 42 |
|
44 | 43 | stationDestinationDeparture['platform'] = platform |
45 | 44 | stationDestinationDeparture['numCars'] = numCars |
|
50 | 49 |
|
51 | 50 | stationDestinations[destination] = stationDestinationDepartures |
52 | 51 |
|
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 | + |
54 | 67 |
|
0 commit comments