Advertisement
rfmonk

monitor.py

Jan 8th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import urllib
  4. from xml.etree.ElementTree import parse
  5.  
  6.  
  7. candidates = ['1765']
  8. daves_latitude = 41.980262
  9.  
  10. def distance(lat1, lat2):
  11.     'Return distance in miles between two lats'
  12.     return 69*abs(lat1 - lat2)
  13.  
  14. def monitor():
  15.     u = urllib.urlopen('http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22')
  16.     doc = parse(u)
  17.     for bus in doc.findall('bus'):
  18.         busid = bus.findtext('id')
  19.         if busid in candidates:
  20.             lat = float(bus.findtext('lat'))
  21.             dis = distance(lat, daves_latitude)
  22.             print busid, dis, 'miles'
  23.     print '-'*10
  24.  
  25.  
  26. import time
  27. while True:
  28.     monitor()
  29.     time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement