Bus time prediction script in USA with python : This script will tell you at what time the nest Bus coming towards your way in Chicago ,USA .
Here i am using following website for route and Bus prediction .
http://ctabustracker.com/bustime/home.jsp
Lets create a file called 1.py and copy the following code to it .
import urllib.request
import sys
if len(sys.argv) !=3:
raise SystemExit('We need route and stopid.')
route=sys.argv[1]
stopid=sys.argv[2]
u=urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop={}&route={}'.format(stopid,route))
data=u.read()
from xml.etree.ElementTree import XML
doc=XML(data)
for pt in doc.findall('.//pt'):
print(pt.text)
Now save the file and run this as : python3.4 1.py 22 14787
here 22 is route and 14787 is bus-stop .
You will get following result :
Enjoy . :)
Connect With Me: Facebook
Here i am using following website for route and Bus prediction .
http://ctabustracker.com/bustime/home.jsp
Lets create a file called 1.py and copy the following code to it .
import urllib.request
import sys
if len(sys.argv) !=3:
raise SystemExit('We need route and stopid.')
route=sys.argv[1]
stopid=sys.argv[2]
u=urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop={}&route={}'.format(stopid,route))
data=u.read()
from xml.etree.ElementTree import XML
doc=XML(data)
for pt in doc.findall('.//pt'):
print(pt.text)
Now save the file and run this as : python3.4 1.py 22 14787
here 22 is route and 14787 is bus-stop .
You will get following result :
Enjoy . :)
Connect With Me: Facebook