-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitor.py
More file actions
35 lines (27 loc) · 777 Bytes
/
monitor.py
File metadata and controls
35 lines (27 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 29 20:11:03 2017
@author: PeaceDove
"""
# monitor.py
import urllib
from xml.etree.cElementTree import parse
candidates = ['1866', '1383', '4367']
daves_lat =41.980262
def distance(lat1, lat2):
'Return distance in miles between two lats'
return 69 * abs(lat1 - lat2)
def monitor():
u = urllib.urlopen('http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22')
doc = parse(u)
for bus in doc.findall('bus'):
busid = bus.findtext('id')
if busid in candidates:
lat = float(bus.findtext('lat'))
dis = distance(lat, daves_lat)
print busid, dis, ' Miles'
print '--'*10
import time
while True:
monitor()
time.sleep(60)