def index(): """ 1. grab ingredient list 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.form.get('ingredient_list') recipe = [] try: response = api.get_ingredients(ingredient_list) recipe = random.choice(response["matches"]) result = { "recipe_id": recipe["id"], "recipe_name": recipe["recipeName"], "recipe_pic": recipe['imageUrlsBySize']['90'].replace( 's90-c', 's230-c' ) } code = 200 except: # silencing all errors - bad! result = {"sorry": "Something went terribly wrong!"} code = 404 return make_response(jsonify(result), code) else: return render_template("index.html")
def index(): """ 1. grab ingredient list from form 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.form.get('ingredient_list') recipe = [] try: response = api.get_ingredients(ingredient_list) recipe = random.choice(response["matches"]) result = { "recipe_id": recipe["id"], "recipe_name": recipe["recipeName"], "recipe_pic": recipe['imageUrlsBySize']['90'].replace( 's90-c', 's230-c' ) } code = 200 except requests.ConnectionError, e: result = {"error": e} code = 500 except:
def index(): """ 1. grab ingredient list from form 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.form.get('ingredient_list') recipe = [] try: # REFACTOR TRY/EXCEPT response = api.get_ingredients(ingredient_list) recipe = random.choice(response["matches"]) print response ingredients = [] for i in recipe['ingredients']: ingredients.append(i) try: image = recipe['imageUrlsBySize']['90'].replace( 's90-c', 's230-c') except: image = 'https://static.apitools.com/logos/yummly.png' result = { "recipe_id": recipe["id"], "recipe_name": recipe["recipeName"], "recipe_pic": image, "recipe_rating": recipe['rating'], "recipe_ingredients": ingredients } code = 200 except requests.ConnectionError: result = {"sorry": "Sorry, your connection isn't working! Fix it!"} code = 500 except: result = {"sorry": "Sorry, no results! Please try again."} code = 500 print result return jsonify(result), code else: return render_template("index.html")
def index(): """ 1. grab ingredient list from form 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.form.get('ingredient_list') recipe = [] try: response = api.get_ingredients(ingredient_list) recipe = random.choice(response["matches"]) ingredients = [] for i in recipe['ingredients']: ingredients.append(i) result = { "recipe_id": recipe["id"], "recipe_name": recipe["recipeName"], "recipe_pic": recipe['imageUrlsBySize']['90'].replace('s90-c', 's230-c'), "recipe_rating": recipe['rating'], "recipe_flavors": recipe['flavors'], "recipe_ingredients": ingredients } code = 200 except: # silencing all errors result = {"sorry": "Sorry, no results! Please try again."} code = 500 return jsonify(result), code else: return render_template("index.html")
def index(): """ 1. grab ingredient list from form 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.form.get('ingredient_list') recipe = [] try: response = api.get_ingredients(ingredient_list) recipe = random.choice(response["matches"]) ingredients = [] for i in recipe['ingredients']: ingredients.append(i) result = { "recipe_id": recipe["id"], "recipe_name": recipe["recipeName"], "recipe_pic": recipe['imageUrlsBySize']['90'].replace( 's90-c', 's230-c'), "recipe_rating": recipe['rating'], "recipe_flavors": recipe['flavors'], "recipe_ingredients": ingredients } code = 200 except: # silencing all errors result = {"sorry": "Sorry, no results! Please try again."} code = 500 return jsonify(result), code else: return render_template("index.html")
def index(): """ 1. grab ingredient list from form 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.values.get('ingredient') try: response = api.get_ingredients(ingredient_list) single_recipe = random.choice(response["matches"]) except: # silencing all errors - bad! ERRORS.append("Something went wrong!") return render_template( "index.html", recipe=single_recipe, recipes=response, errors=ERRORS ) else: return render_template("index.html")
def index(): """ 1. grab ingredient list from form 2. pass ingredients list to `get_ingredients()` 3. grab random result 3. return results to the template """ if request.method == "POST": ingredient_list = request.values.get('ingredient') try: response = api.get_ingredients(ingredient_list) single_recipe = random.choice(response["matches"]) except: # silencing all errors - bad! ERRORS.append("Something went wrong!") return render_template("index.html", recipe=single_recipe, recipes=response, errors=ERRORS) else: return render_template("index.html")