import urllib
from xml.etree.ElementTree import parse
candidates = ['4198', '4168']
daves_latitude = 41.98062
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_latitude)
print busid, dis, 'miles'
print '-'*10
import time
while True:
monitor()
time.sleep(60)
I did this exercise based on a real life problem. Dave forgets his case in the bus, and he wants to find out wich one of the canditate buses is carrying the lost case. I understand the code, but I can't find out the relationship between the first function and the second one, as
def distance(lat1, lat2):
'Return distance in miles between two lats'
return 69*abs(lat1 - lat2)
I understand what monitor() does but not the relationship between distance() and monitor() and how they interact to show the results, can you please enlighten me ? I am a n00b.
Thanks