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
|
|
|
|
|
from application.db import Session, Recipe, Ingredient
|
2020-04-17 20:29:50 +00:00
|
|
|
import search
|
|
|
|
|
import 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-25 16:53:32 +00:00
|
|
|
ingreds = [migrate.stem(ingred)[0] for ingred in ingreds]
|
2020-04-20 21:31:04 +00:00
|
|
|
|
|
|
|
|
start = time.time()
|
2020-04-24 20:00:15 +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-25 16:53:32 +00:00
|
|
|
#start = time.time()
|
|
|
|
|
recs = search.getRecDict2(indx, ingreds)
|
2020-04-20 21:31:04 +00:00
|
|
|
end = time.time()
|
|
|
|
|
print("calc overlay",end - start, "\n")
|
|
|
|
|
|
|
|
|
|
g.session.commit()
|
|
|
|
|
g.session.close()
|
|
|
|
|
return flask.make_response(flask.jsonify({'data': recs}), 200)
|
|
|
|
|
|
2020-04-10 14:14:34 +00:00
|
|
|
|
|
|
|
|
|