Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import urllib.request
import json
from pprint import pprint
urlRequest = "https://maps.googleapis.com/maps/api/place/textsearch/json?"
apiKey = "AIzaSyD1pMiJyDTK5V-ayhWnpNm5FHSXly4TeLk"
finalPoint = "https://maps.googleapis.com/maps/api/directions/json?"
place= input("what place are you looking for? ").replace(",", " in " )
# this function finds the place in specific area
def placesFound(place):
place = place.replace(" ","+")
parameters = "key={}&query={}".format ( apiKey, place )
dest=[]
request = urlRequest + parameters
response = urllib.request.urlopen(request).read()
places = json.loads(response)
for i in range(0,len(places["results"])):
results = places["results"][i]['formatted_address']
dest.append(results)
return dest
# ToDO: chech for empty list
for item in placesFound(place) :
print(item +"\n")
num = input("which one of the following addresses is the best for you, select the address with number from 1 to 5? ?>>> " )
def indexNumber(num):
num = int(num)
num -=1
return num
destination= placesFound(place)[indexNumber(num)]
origin = input("where are you ? >>> ")
def directions(origin, destination):
origin=origin.replace(' ','')
destination=destination.replace(' ','')
stepSummary=[]
navRequest = "origin={}&destination={}&key={}" . format ( origin, destination , apiKey)
request = finalPoint + navRequest
response = urllib.request.urlopen(request).read()
directions = json.loads(response)
# ToDO: chech for empty list
legs = directions["routes"][0]["legs"]
for leg in legs :
steps = leg["steps"]
for step in steps:
stepSummaryary=(step['html_instructions'].replace("0.9em","").replace("style","").replace(":","").replace("div","").replace("font-size","").replace('"',"").replace("</b>","").replace("<b>"," ").replace("</div >"," ").replace("<div >"," ").replace("="," ").replace('<div style"font-size:0.9em">'," "))
stepSummary.append(stepSummaryary)
return stepSummary
route=(directions(origin,destination))
def cleanText(route):
steps=[]
for step in route:
for letter in step:
letter=letter.replace('<','')
letter=letter.replace('>','')
steps.append(step)
return steps
for item in cleanText(route):
print(item +"\n")