dabeaz-course/practical-python

Getting 404 when I try to run the exercise 1.4

Opened this issue · 2 comments

Thanks a lot for making this course!!!

It looks like something has changed on the bus tracker website and the example code gets an http return code 404. It seems like the URL should be updated to make the exercise work.

I've added a note to the exercise about the API being deprecated. Sadly, I don't think I can modify the exercise to make it work as the bus-tracker now requires its users to sign up for an API key.

asett commented

Hi @dabeaz / @ikasovitch ,

I was able to modify the code for the CTA Bus Tracker and get it to work.
It does require the use of an API key, however it's quite easy to get an API key and then start using the API.

Here's the modified code:

import urllib.request
u = urllib.request.urlopen('http://www.ctabustracker.com/bustime/api/v2/getpredictions?key=ADD_YOUR_API_KEY_HERE&rt=22&stpid=14791')
from xml.etree.ElementTree import parse
doc = parse(u)
print("Arrival time in minutes:")
for pt in doc.findall('.//prdctdn'):
        print(pt.text)