-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (36 loc) · 1.41 KB
/
app.py
File metadata and controls
39 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, render_template, request
import json
application = Flask(__name__)
mealTypes = ["Breakfast", "Lunch", "Dinner", "Dessert", "SnacksAndApps"]
@application.route('/', methods=["GET","POST"])
def home():
if request.method == "POST":
startIngredients = []
startIngredients = ((str)(request.form["Ingredients"])).split(", ")
mealTypeInput = (str)(request.form["mealType"])
if mealTypeInput == "Any":
for mealType in mealTypes:
f = open(""+mealType+".json")
recipeList = json.load(f)
data = []
for recipe in recipeList:
for item in recipeList[recipe]:
for ingredient in startIngredients:
if ingredient in item and recipeList[recipe] not in data:
data.append(recipeList[recipe])
elif mealTypeInput == "Selection":
return render_template("base.html", output_data = [])
else:
f = open(""+mealTypeInput+".json")
recipeList = json.load(f)
data = []
for recipe in recipeList:
for item in recipeList[recipe]:
for ingredient in startIngredients:
if ingredient in item and recipeList[recipe] not in data:
data.append(recipeList[recipe])
return render_template("base.html", output_data = data)
if request.method == "GET":
return render_template("base.html", output_data = [])
if __name__=="__main__":
application.run(debug=True)