def display_search_results(): """Display search results.""" search_term = request.args.get("keyword") location_term = request.args.get("location") if not location_term: location_term = "San Francisco" # Yelp API call with user input values search_results = yelp.search_query(term=search_term, location=location_term, category_filter="food,restaurants", limit=10) # result is the list of restaurant dictionaries result = search_results['businesses'] # For each restaurant, add its open status and wait time info to their dictionary for restaurant in result: add_open_status(restaurant) add_wait_info(restaurant) # Handle sorting sort_value = request.args.get("sort_by") result = sorted_result(result, sort_value) # Handle filtering selected_filters = request.args.getlist("filter_by") result = filtered_result(result, selected_filters) # Add result to result_dict, which will be converted to a JSON through Jinja result_dict = {'result': result} return render_template("results.html", result=result, key=BROWSER_KEY, result_dict=result_dict, search_term=search_term, location_term=location_term)
def test_add_open_status_with_mock_none(self): """Tests adding open status ("Open now unknown") to restaurant dictionary.""" restaurant_mock = {"rating": 4.0, "rating_img_url": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png", "review_count": 1983, "name": "Ryoko's", "rating_img_url_small": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png", "url": "http://www.yelp.com/biz/ryokos-san-francisco?utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=6XuCRI2pZ5pIvcWc9SI3Yg", "image_url": "https://s3-media4.fl.yelpcdn.com/bphoto/El1KekyVFSqrtKLAyjcfNA/ms.jpg", "display_phone": "+1-415-775-1028", "id": "ryokos-san-francisco", "location": {"city": "San Francisco", "postal_code": "94102", "address": ["619 Taylor St"], "coordinate": {"latitude": 37.788008004427, "longitude": -122.411782890558}, "state_code": "CA"}} add_open_status(restaurant_mock) self.assertEqual(restaurant_mock["open_now"], "Open now unknown")