from urllib.request import urlopen
from xml.etree.ElementTree import parse
import time, webbrowser

class Bus:
	def __init__(self, busid=0, latitude=0.0, longitude=0.0):
		self.busid = busid
		self.latitude = latitude
		self.longitude = longitude

	def __str__(self):
		return ('%s %s\t%s' % (self.busid, self.latitude, self.longitude))

	def coordinates(self):
		return "%s, %s" % (self.latitude, self.longitude)

def get_map(bus_list):
	b_map = 'https://m...content-available-to-author-only...s.com/maps/api/staticmap?center=41.980262,-87.668452&zoom=12&size=800x600&maptype=roadmap'
	#add marks to map adress
	marks = '&markers='
	for bus in bus_list:
		marks += '%s,%s|' % (bus.latitude, bus.longitude)
	print(b_map+marks.rstrip('|'))
	webbrowser.open(b_map+marks)



def main():
	u = urlopen('http://c...content-available-to-author-only...r.com/bustime/map/getBusesForRoute.jsp?route=22')
	data = u.read()
	f = open('rt22.xml', 'wb')
	f.write(data)
	f.close()
	bus_list = []
	doc = parse('rt22.xml')
	for bus in doc.findall('bus'):
		b = Bus()
		b.busid = bus.findtext('id')
		b.latitude = bus.findtext('lat')
		b.longitude = bus.findtext('lon')
		print(b)
		bus_list.append(b)
	get_map(bus_list)



while True:
	main()
	print('-'*40)
	time.sleep(90)