fork download
  1. from urllib.request import urlopen
  2. from xml.etree.ElementTree import parse
  3. import time, webbrowser
  4.  
  5. class Bus:
  6. def __init__(self, busid=0, latitude=0.0, longitude=0.0):
  7. self.busid = busid
  8. self.latitude = latitude
  9. self.longitude = longitude
  10.  
  11. def __str__(self):
  12. return ('%s %s\t%s' % (self.busid, self.latitude, self.longitude))
  13.  
  14. def coordinates(self):
  15. return "%s, %s" % (self.latitude, self.longitude)
  16.  
  17. def get_map(bus_list):
  18. 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'
  19. #add marks to map adress
  20. marks = '&markers='
  21. for bus in bus_list:
  22. marks += '%s,%s|' % (bus.latitude, bus.longitude)
  23. print(b_map+marks.rstrip('|'))
  24. webbrowser.open(b_map+marks)
  25.  
  26.  
  27.  
  28. def main():
  29. u = urlopen('http://c...content-available-to-author-only...r.com/bustime/map/getBusesForRoute.jsp?route=22')
  30. data = u.read()
  31. f = open('rt22.xml', 'wb')
  32. f.write(data)
  33. f.close()
  34. bus_list = []
  35. doc = parse('rt22.xml')
  36. for bus in doc.findall('bus'):
  37. b = Bus()
  38. b.busid = bus.findtext('id')
  39. b.latitude = bus.findtext('lat')
  40. b.longitude = bus.findtext('lon')
  41. print(b)
  42. bus_list.append(b)
  43. get_map(bus_list)
  44.  
  45.  
  46.  
  47. while True:
  48. main()
  49. print('-'*40)
  50. time.sleep(90)
Runtime error #stdin #stdout #stderr 0.07s 58480KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1107, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 694, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./prog.py", line 48, in <module>
  File "./prog.py", line 29, in main
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>