[Solved] python script from youtube video doesn’t work


I am pretty sure this is all the code needed for the video, It might help as a reference.

import urllib
import webbrowser
import time
from xml.etree.ElementTree import parse

u = urllib.urlopen("http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22")
data = u.read()

with open("rt22.xml", "wb") as f:
    f.write(data)
    f.close()

office_lat = 41.980262
doc = parse("rt22.xml")


def distance(lat1, lat2):
    'Return approx miles between lat1 and lat2'
    return 69 * abs(lat1 - lat2)


def check_bus_location():
    for bus in doc.findall("bus"):
        if bus.findtext("lat") >= office_lat:
            latitude = float(bus.findtext("lat"))
            longitude = float(bus.findtext("lon"))
            bus_id = (bus.findtext("id"))
            direction = bus.findtext("d")
            north_buses = [[bus_id, latitude, longitude]]
            if direction.startswith("North"):
                print('%s %s %0.2f miles' % (bus_id, direction, distance(latitude, office_lat)))
                for bus in north_buses:
                    if distance(float(latitude), office_lat) < 0.5:
                        print(webbrowser.open(
                            'http://maps.googleapis.com/maps/api/staticmap?size=500x500&sensor=false&markers=|%f,%f' % (
                                latitude, longitude)))


while True:
    check_bus_location()
    time.sleep(10)

4

solved python script from youtube video doesn’t work