diff --git a/mapqeust b/mapqeust new file mode 100644 index 0000000..a2e39f9 --- /dev/null +++ b/mapqeust @@ -0,0 +1,60 @@ +import urllib.parse +import requests + +main_api = "https://www.mapquestapi.com/directions/v2/route?" +key = "aXced6NG8EtfGmVNZU2hZaKjCJlJH3gI" + +while True: + orig = input("Starting Location: ") + if orig == "quit" or orig == "q": + break + dest = input("Destination: ") + if dest == "quit" or dest == "q": + break + url = main_api + urllib.parse.urlencode({"key": key, "from":orig, "to":dest}) + print("URL: " + (url)) + json_data = requests.get(url).json() + json_status = json_data["info"]["statuscode"] + if json_status == 0: + print("API Status: " + str(json_status) + " = A successful route call.\n") + print("=============================================") + print("Directions from " + (orig) + " to " + (dest)) + print("Trip Duration: " + (json_data["route"]["formattedTime"])) + print("Kilometers: " + str("{:.2f}".format((json_data["route"]["distance"])*1.61))) + print("Fuel Used (Ltr): " + str("{:.2f}".format((json_data["route"]["fuelUsed"])*3.78))) + print("=============================================") + for each in json_data["route"]["legs"][0]["maneuvers"]: + print((each["narrative"]) + " (" + str("{:.2f}".format((each["distance"])*1.61) + " km)")) + print("=============================================") + print("Additional Information") + tollRoad = json_data["route"]["hasTollRoad"] #inform users if there are toll fees ahead + if tollRoad == 0: + print("Toll Road: None") + else: + print("Toll Road: Yes") + seasonalClosure = json_data["route"]["hasSeasonalClosure"] #inform users if there are seasonal closures ahead + if seasonalClosure == 0: + print("Seasonal Clsoure:None") + else: + print("Seasonal Closure:Yes") + countryCross = json_data["route"]["hasCountryCross"] #inform users if they will be crossing another country to prepare for border inspections + if countryCross == 0: + print("Cross Country: None") + else: + print("Cross Country: Yes") + print("Dest Latitude: " + str(json_data["route"]["boundingBox"]["lr"]["lat"])) #for a more accurate waze navigation + print("Dest Longitude: " + str(json_data["route"]["boundingBox"]["lr"]["lng"])) #for a more accurate waze navigation + print("=============================================\n") + elif json_status == 402: + print("********************************************") + print("Status Code: " + str(json_status) + "; Invalid user inputs for one or both locations.") + print("**********************************************\n") + elif json_status == 611: + print("********************************************") + print("Status Code: " + str(json_status) + "; Missing an entry for one or both locations.") + print("**********************************************\n") + else: + print("**********************************************************************") + print("For Staus Code: " + str(json_status) + "; Refer to:") + print("https://developer.mapquest.com/documentation/directions-api/status-codes") + print("************************************************************************\n")