2020-04-10 14:14:34 +00:00
|
|
|
from flask_restful import Resource, reqparse
|
|
|
|
|
import flask
|
2020-04-20 21:31:04 +00:00
|
|
|
from flask import g
|
2020-04-10 14:14:34 +00:00
|
|
|
import requests
|
|
|
|
|
import application.config as config
|
|
|
|
|
import json
|
|
|
|
|
import base64
|
2020-04-26 21:44:25 +00:00
|
|
|
from application.db2 import Session, Recipe
|
|
|
|
|
import application.search as search
|
|
|
|
|
import background.migrate as migrate
|
2020-04-18 08:18:13 +00:00
|
|
|
import time
|
2020-04-10 14:14:34 +00:00
|
|
|
|
2020-04-17 20:29:50 +00:00
|
|
|
class RecipeList(Resource):
|
2020-04-10 14:14:34 +00:00
|
|
|
def get(self):
|
|
|
|
|
""" """
|
2020-04-20 21:31:04 +00:00
|
|
|
g.session = Session()
|
2020-04-23 16:44:10 +00:00
|
|
|
g.session = Session()
|
2020-04-20 21:31:04 +00:00
|
|
|
parser = reqparse.RequestParser()
|
|
|
|
|
parser.add_argument('ingred', type=str, action='append')
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
ingreds = args["ingred"]
|
|
|
|
|
|
2020-04-26 21:44:25 +00:00
|
|
|
ingreds = [migrate.stem(ingred)[0] for ingred in ingreds]
|
2020-04-20 21:31:04 +00:00
|
|
|
|
|
|
|
|
start = time.time()
|
2020-04-26 21:44:25 +00:00
|
|
|
indx = search.search2(ingreds)
|
2020-04-20 21:31:04 +00:00
|
|
|
end = time.time()
|
|
|
|
|
print("get recipes",end - start, "\n")
|
|
|
|
|
|
2020-04-26 21:44:25 +00:00
|
|
|
recs = search.getRecDict2(indx, ingreds)
|
2020-04-20 21:31:04 +00:00
|
|
|
end = time.time()
|
|
|
|
|
print("calc overlay",end - start, "\n")
|
|
|
|
|
|
|
|
|
|
g.session.close()
|
|
|
|
|
return flask.make_response(flask.jsonify({'data': recs}), 200)
|
|
|
|
|
|
2020-04-26 21:44:25 +00:00
|
|
|
class Images(Resource):
|
|
|
|
|
def get(self, id = None):
|
|
|
|
|
if id is None:
|
|
|
|
|
flask.make_response(flask.jsonify({'error': "No ID supplied"}), 401)
|
|
|
|
|
|
|
|
|
|
session = Session()
|
|
|
|
|
image = session.query(Recipe.img).filter(Recipe.recipe_id == id).first()[0]
|
2020-04-27 12:13:13 +00:00
|
|
|
image = base64.b64decode(image)
|
2020-04-29 21:10:31 +00:00
|
|
|
session.close()
|
2020-04-26 21:44:25 +00:00
|
|
|
return flask.Response(image, mimetype='image/png')
|
|
|
|
|
|
2020-04-10 14:14:34 +00:00
|
|
|
|
|
|
|
|
|