def time(self): url = _base_url + 'gettime' result = requests.get(url, params={'key': self.key}) xml = xmltodict.parse(result.text) if 'tm' in list(xml['bustime-response'].keys()): time_str = xml['bustime-response']['tm'] return _time_translation(time_str) else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def time(self): url = _base_url + 'gettime' result = requests.get(url, params={'key': self.key}) xml = xmltodict.parse(result.text) if 'tm' in xml['bustime-response'].keys(): time_str = xml['bustime-response']['tm'] return _time_translation(time_str) else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def routes(self, update=False): if (hasattr(self, 'bus_routes') and self.bus_routes != [] and update is False): return self.bus_routes url = _base_url + 'getroutes' result = requests.get(url, params={'key': self.key}) xml = xmltodict.parse(result.text) if 'error' in list(xml['bustime-response'].keys()): errors.error_handler(xml['bustime-response']['error']['msg']) self.bus_routes = [] for resp in xml['bustime-response']['route']: rt = BusTracker.Route(resp['rt'], self, resp['rtnm']) self.bus_routes.append(rt) return self.bus_routes
def routes(self, update=False): if ( hasattr(self, 'bus_routes') and self.bus_routes != [] and update is False ): return self.bus_routes url = _base_url + 'getroutes' result = requests.get(url, params={'key': self.key}) xml = xmltodict.parse(result.text) if 'error' in xml['bustime-response'].keys(): errors.error_handler(xml['bustime-response']['error']['msg']) self.bus_routes = [] for resp in xml['bustime-response']['route']: rt = BusTracker.Route(resp['rt'], self, resp['rtnm']) self.bus_routes.append(rt) return self.bus_routes
def bus_by_id(self, vid): url = _base_url + 'getvehicles' result = requests.get(url, params={'key': self.key, 'vid': vid}) xml = xmltodict.parse(result.text) if 'vehicle' in list(xml['bustime-response'].keys()): v_data = xml['bustime-response']['vehicle'] time = v_data['tmstmp'] latitude = v_data['lat'] longitude = v_data['lon'] heading = v_data['hdg'] pattern_id = v_data['pid'] route = v_data['rt'] destination = v_data['des'] pattern_dist = v_data['pdist'] speed = v_data['spd'] bus = BusTracker.Bus(vid, self, time, latitude, longitude, heading, pattern_id, pattern_dist, route, destination, speed) return bus else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def stops(self, direction, update=False): assert (direction in self.directions()) url = _base_url + 'getstops' params = {'key': self.bt.key, 'rt': self.number, 'dir': direction} result = requests.get(url, params=params) xml = xmltodict.parse(result.text) if hasattr(self, 'stop') and not update: return self.stops elif 'stop' in list(xml['bustime-response'].keys()): self.stop = [] for resp in xml['bustime-response']['stop']: id = resp['stpid'] name = resp['stpnm'] latitude = resp['lat'] longitude = resp['lon'] stop = BusTracker.Stop(id, name, latitude, longitude, self.bt) self.stop.append(stop) return self.stop else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def bus_by_id(self, vid): url = _base_url + 'getvehicles' result = requests.get(url, params={'key': self.key, 'vid': vid}) xml = xmltodict.parse(result.text) if 'vehicle' in xml['bustime-response'].keys(): v_data = xml['bustime-response']['vehicle'] time = v_data['tmstmp'] latitude = v_data['lat'] longitude = v_data['lon'] heading = v_data['hdg'] pattern_id = v_data['pid'] route = v_data['rt'] destination = v_data['des'] pattern_dist = v_data['pdist'] speed = v_data['spd'] bus = BusTracker.Bus(vid, self, time, latitude, longitude, heading, pattern_id, pattern_dist, route, destination, speed) return bus else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def stops(self, direction, update=False): assert(direction in self.directions()) url = _base_url + 'getstops' params = {'key': self.bt.key, 'rt': self.number, 'dir': direction} result = requests.get(url, params=params) xml = xmltodict.parse(result.text) if hasattr(self, 'stop') and not update: return self.stops elif 'stop' in xml['bustime-response'].keys(): self.stop = [] for resp in xml['bustime-response']['stop']: id = resp['stpid'] name = resp['stpnm'] latitude = resp['lat'] longitude = resp['lon'] stop = BusTracker.Stop(id, name, latitude, longitude, self.bt) self.stop.append(stop) return self.stop else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def busses(self, update=False): url = _base_url + 'getvehicles' params = {'key': self.bt.key, 'rt': self.number} result = requests.get(url, params=params) xml = xmltodict.parse(result.text) if 'vehicle' in list(xml['bustime-response'].keys()): for resp in xml['bustime-response']: vid = resp['vid'] time = resp['tmstmp'] latitude = resp['lat'] longitude = resp['lon'] heading = resp['hdg'] pattern_id = resp['pid'] route = resp['rt'] destination = resp['des'] pattern_dist = resp['pdist'] speed = resp['spd'] bus = BusTracker.Bus(vid, self, time, latitude, longitude, heading, pattern_id, pattern_dist, route, destination, speed) self.busses.append(bus) else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)
def busses(self, update=False): url = _base_url + 'getvehicles' params = {'key': self.bt.key, 'rt': self.number} result = requests.get(url, params=params) xml = xmltodict.parse(result.text) if 'vehicle' in xml['bustime-response'].keys(): for resp in xml['bustime-response']: vid = resp['vid'] time = resp['tmstmp'] latitude = resp['lat'] longitude = resp['lon'] heading = resp['hdg'] pattern_id = resp['pid'] route = resp['rt'] destination = resp['des'] pattern_dist = resp['pdist'] speed = resp['spd'] bus = BusTracker.Bus(vid, self, time, latitude, longitude, heading, pattern_id, pattern_dist, route, destination, speed) self.busses.append(bus) else: error = xml['bustime-response']['error']['msg'] errors.error_handler(error)