-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.py
52 lines (42 loc) · 1.74 KB
/
routes.py
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
from flask import Flask, request, render_template, url_for, redirect
import tags
from werkzeug import secure_filename
import os
from algoliasearch import algoliasearch
app = Flask(__name__)
myLinks = []
pathNames = []
@app.route('/', methods=['GET', 'POST'])
def index():
n = '\n'
link = None
tagsList = []
if request.method == 'POST' and 'useLink' in request.form:
link = request.form.get('link') #'https://imagesvc.timeincapp.com/v3/mm/image?url=http%3A%2F%2Fimg1.cookinglight.timeinc.net%2Fsites%2Fdefault%2Ffiles%2Fstyles%2Fmedium_2x%2Fpublic%2F1516896485%2Fchicken-paella-ck-1803.jpg%3Fitok%3DBK5uGeSC&w=1600&q=70'request
if link not in pathNames:
myLinks.append(link) # add to record of img links used
tagsList = tags.get_relevant_tags(link)
return render_template(('recipes.html'), tagsList=tagsList, link=link)
elif request.method == 'POST' and 'uploadImg' in request.form:
# use uploaded image
f = request.files['photo']
sfname = str(os.path.join('static/img/',str(secure_filename(f.filename))))
f.save(sfname)
tagsList = tags.get_relevant_tags_file(sfname)
return render_template(('recipes.html'), tagsList=tagsList, link=sfname)
return render_template('index.html')
@app.route('/recipes', methods=['GET', 'POST'])
def recipes():
return render_template('recipes.html', tagsList=tagsList, link=link)
@app.route('/prep', methods=['GET', 'POST'])
def prep():
pathNames = []
for filename in os.listdir(os.path.dirname('static/img/')):
pathNames.append(filename)
#mydict = tags.get_foodspo(pathNames, myLinks)
return render_template('prep.html', myLinks=myLinks,pathNames=pathNames)
@app.route('/foodspo', methods=['GET', 'POST'])
def foodspo():
return render_template('foodspo.html')
if __name__=='__main__':
app.run(debug=True)