-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (54 loc) · 2.37 KB
/
Copy pathapp.py
File metadata and controls
75 lines (54 loc) · 2.37 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from dotenv import load_dotenv
from flask import Flask, render_template, request
import pages.toRecipe as toRecipe
import os
app = Flask(__name__)
@app.route('/')
@app.route('/home')
@app.route('/home.html', methods = ["POST"])
def home():
form_data = request.form
inputAPIKey = None
if load_dotenv():
print(f'### load .env file')
inputAPIKey = os.getenv('OPENAI_API_KEY')
elif request.method == 'POST' and form_data.get('inputAPIKey'):
inputAPIKey = form_data.get('inputAPIKey')
if inputAPIKey is not None:
print(f'### OPENAI_API_KEY : {inputAPIKey}')
return render_template('home.html', OpenAIAPIKey=inputAPIKey)
@app.route('/toRecipe', methods = ["GET", "POST"])
def recipe():
try:
print(f'### {request.full_path} : {request.method}')
if request.method == 'GET':
return render_template('toRecipe.html')
form_data = request.form
print(f'### form_data : {form_data}')
# from toRecipe.html to these pages
if request.method == 'POST' and form_data.get('inputStaples'):
ingredients = form_data['inputStaples']
staples_list = form_data.getlist('listStaples') # 'butter', 'oil', 'water', 'salt', 'pepper'
print(f'### stape list {type(staples_list)} : {staples_list}')
staples = ""
staples = ", ".join(staples_list)
print(f'### list to String : {staples}')
if len(ingredients.strip()) == 0:
print('Not enough ingredients inputted')
return render_template('error.html')
else:
lorn, lingr, lop, lurl = toRecipe.combine(ingredients, staples)
# image_url = lurl[0]
# recipes = lorn[0]
# return render_template('toRecipe.html', recipe_name=recipes, image_url=image_url, recipes=lurl)
return render_template('toRecipeImg.html', recipe_name=lorn, image_url=lurl)
else:
return render_template('toRecipe.html')
except Exception as e:
print('Error Occurred: ', e)
return render_template('error.html')
@app.route('/pantryTracker')
def ingredients():
return render_template('pantryTracker.html')
if __name__ == '__main__':
app.run('0.0.0.0', port=80, debug=True)