def yelpSearch(ll, term): try: busDict=search(term, str(ll[0])+","+str(ll[1])) except urllib2.HTTPError as error: sys.exit('Encountered HTTP error {0}. Abort program.'.format(error.code)) businesses=busDict.get('businesses') businessList=[] print(businesses) for i in businesses: url=i['url'] name=i['name'] loc=i['location'] rating=i['rating'] cBus={} if 'image_url' in i.keys(): image=i['image_url'] cBus["image_url"]=image else: cBus["image_url"]=None if 'rating_img_url' in i.keys(): rating_url=i['rating_img_url'] cBus['rating_images_url']=rating_url else: cBus['irating_images_url']=None lat=loc['coordinate']['latitude'] lng=loc['coordinate']['longitude'] address=loc['display_address'] cBus["rating"]=rating cBus["url"]=url cBus["name"]=name cBus["lat"]=lat cBus["lng" ]=lng cBus["rer"]=i['review_count'] cBus["add"]=address businessList.append(cBus) businessJson={} businessJson["businesses"]=businessList return json.dumps(businessJson)
def getTimes(ll,peeps): key = 'AIzaSyDrXFWbkfQSZ9ayLS-XUWjOnKrs1x440eA' client = googlemaps.Client(key) if not ll: ll="40.4435480,-79.9446180" term="" rests=search(term, ll) businesses = rests.get('businesses') if not businesses: print u'No businesses for {0} in {1} found.'.format(term, ll) quit() ndes=len(businesses) origins=peeps destinations=[] for x in range(ndes): destinations.append( { 'lat' : businesses[x]['location']['coordinate']['latitude'], 'lng' : businesses[x]['location']['coordinate']['longitude'] } ) matrix = client.distance_matrix(origins, destinations, mode="driving", units="imperial", departure_time="now") # times = [[1,2,3],[4,5,6]], where 1,2,3 are the amounts of time it takes for the first person to get to shop 1, shop 2, and shop 3 respectively, and 4,5,6 are the times it takes for person 2 to go to shop 1, shop 2, and shop 3. times=[] ind=0 for pers in matrix['rows']: times.append([]) for place in pers['elements']: times[ind].append(place['duration']['text']) ind+=1 return times
def search(): query = request.args["query"] restaurant_list = restaurants.search(query) return render_template("restaurantlist.html", restaurants=restaurant_list)