Skip to content

Commit 2d36223

Browse files
committed
Incorporated issue #157
1 parent 3c00ff8 commit 2d36223

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Notes/01_Introduction/01_Python.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ I taught this course in my office. You could query the bus and then
150150
literally watch it pass by the window out front. Sadly, APIs rarely live
151151
forever and it seems that this one has now ridden off into the sunset. --Dave
152152

153+
Update: GitHub user @asett has suggested the following modified code might work,
154+
but you'll have to provide your own API key (available [here](https://www.transitchicago.com/developers/bustracker/)).
155+
156+
```python
157+
import urllib.request
158+
u = urllib.request.urlopen('http://www.ctabustracker.com/bustime/api/v2/getpredictions?key=ADD_YOUR_API_KEY_HERE&rt=22&stpid=14791')
159+
from xml.etree.ElementTree import parse
160+
doc = parse(u)
161+
print("Arrival time in minutes:")
162+
for pt in doc.findall('.//prdctdn'):
163+
print(pt.text)
164+
```
165+
166+
(Original exercise example follows below)
167+
153168
Try something more advanced and type these statements to find out how
154169
long people waiting on the corner of Clark street and Balmoral in
155170
Chicago will have to wait for the next northbound CTA \#22 bus:

0 commit comments

Comments
 (0)