def initialize(output: str) -> object: if output == 'ELEVATION': initial_elevation = mapquest.check_result( mapquest.build_elevation_url( mapquest.return_first_latlongs(route_data))) initial_obj = create_object(output, initial_elevation) obj = create_object(output, elevation_data) initial_obj.add(obj.peek()[0]) return initial_obj else: return create_object(output, route_data)
def get_data(self) -> list: latlong_lst = [] elevation_lst = [] for location in self.json_result["route"]["locations"]: latlong_lst.append((str(location["latLng"]["lat"]), str(location["latLng"]["lng"]))) for latlong in latlong_lst: elevation_url = mapquest.build_elevation_url(latlong) json_elevation_result = mapquest.get_elevation_result( elevation_url) for elevation in json_elevation_result["elevationProfile"]: elevation_lst.append(round(elevation["height"])) return elevation_lst
def print_info(self) -> None: """ Prints elevations of each location """ route_url = mapquest.build_route_url(self._locations) result = mapquest.get_result(route_url) print("ELEVATIONS") for location in result["route"]["locations"]: lat = float(location["latLng"]["lat"]) long = float(location["latLng"]["lng"]) elevation_url = mapquest.build_elevation_url(lat, long) elevation_result = mapquest.get_result(elevation_url) elevation = round( elevation_result["elevationProfile"][0]["height"]) print(elevation) print()
def user_interface(): loc_list = [] output_list = [] loc_number = input("Input the number of locations ") for i in range(int(loc_number)): a = input("Input location: ") loc_list.append(a) output_number = input("Input the number of outputs you want ") for j in range(int(output_number)): b = input("Input kind of output: ") output_list.append(b) route_result = mapquest.url_dict(mapquest.build_route_url(loc_list)) e = [] for i in route_result['route']['locations']: lat = i['latLng']['lat'] e.append(lat) lng = i['latLng']['lng'] e.append(lng) s = str(e).strip('[]{}') for k in output_list: if k == 'LATLONG': print('LATLONGS') outputs.LATLONG().print_latlong(route_result) elif k == 'STEPS': print('DIRECTIONS') outputs.STEPS().print_steps(route_result) elif k == 'TOTALTIME': outputs.TOTALTIME().print_totaltime(route_result) elif k == 'TOTALDISTANCE': outputs.TOTALDISTANCE().print_totaldistance(route_result) elif k == 'ELEVATION': print('ELEVATIONS') eve_result = mapquest.url_dict(mapquest.build_elevation_url(s)) outputs.ELEVATION().print_elevations(eve_result) print() print( 'Directions Courtesy of MapQuest; Map Data Copyright OpenStreetMap Contributors' )
list_output = read_outputs(num_output) list_of_objects = [] count1 = 0 while count1 < num_location: if count1 == 0: start = list_locations[0] count1 += 1 else: try: route_data = mapquest.check_result( mapquest.build_route_url(start, list_locations[count1])) elevation_data = mapquest.check_result( mapquest.build_elevation_url( mapquest.return_last_latlongs(route_data))) if list_of_objects == []: for output in list_output: obj = initialize(output) list_of_objects.append(obj) else: count2 = 0 while count2 < num_output: if list_output[count2] == 'ELEVATION': element = create_object(list_output[count2], elevation_data) list_of_objects[count2].add(element.peek()[0]) else: element = create_object(list_output[count2], route_data)