dockerized
This commit is contained in:
parent
ca593f6b2f
commit
68added41f
|
|
@ -1,5 +1,4 @@
|
||||||
FROM python
|
FROM python
|
||||||
COPY ./certs /certs
|
|
||||||
|
|
||||||
COPY ./ /app
|
COPY ./ /app
|
||||||
RUN pip install -r /app/requirements.txt
|
RUN pip install -r /app/requirements.txt
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,12 +1,10 @@
|
||||||
from flask import Flask, request, g, render_template
|
from flask import Flask, request, g, render_template
|
||||||
from flask_restful import Resource, reqparse
|
from flask_restful import Resource, reqparse
|
||||||
from flask_restful_swagger_3 import Api
|
from flask_restful_swagger_3 import Api
|
||||||
from flask_cors import CORS
|
|
||||||
import os
|
import os
|
||||||
from json import dumps
|
from json import dumps
|
||||||
import application.endpoints as endpoints
|
import application.endpoints as endpoints
|
||||||
import application.config as config
|
import application.config as config
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
api = Api(app, version='1', contact={"name":""}, license={"name":"Online Dienst Dokumentation"}, api_spec_url='/api/swagger')
|
api = Api(app, version='1', contact={"name":""}, license={"name":"Online Dienst Dokumentation"}, api_spec_url='/api/swagger')
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -4,11 +4,11 @@ from sqlalchemy.orm import sessionmaker, relationship, column_property
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
import enum
|
import enum
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
import time
|
||||||
|
|
||||||
engine = db.create_engine('mysql+mysqldb://root@server/fs?charset=utf8mb4', echo=False, encoding="utf8")
|
engine = db.create_engine('mysql+mysqldb://root@server/fs?charset=utf8mb4', echo=False, encoding="utf8")
|
||||||
connection = engine.connect()
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
Session = sessionmaker(bind=engine)
|
Session = sessionmaker(bind=engine)
|
||||||
|
|
||||||
|
|
@ -72,5 +72,14 @@ class Trunk(Base):
|
||||||
|
|
||||||
recipe_id = Column(Integer, ForeignKey('recipe.recipe_id'))
|
recipe_id = Column(Integer, ForeignKey('recipe.recipe_id'))
|
||||||
|
|
||||||
|
def initDB(counter):
|
||||||
|
try:
|
||||||
|
Base.metadata.create_all(engine)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
counter += 1
|
||||||
|
if counter < 13:
|
||||||
|
time.sleep(5)
|
||||||
|
initDB(counter)
|
||||||
|
|
||||||
Base.metadata.create_all(engine)
|
initDB(0)
|
||||||
|
|
@ -12,17 +12,13 @@ import time
|
||||||
class RecipeList(Resource):
|
class RecipeList(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
""" """
|
""" """
|
||||||
|
try:
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument('ingred', type=str, action='append')
|
parser.add_argument('ingred', type=str, action='append')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
ingreds = args["ingred"]
|
ingreds = args["ingred"]
|
||||||
|
|
||||||
start = time.time()
|
|
||||||
ingreds = [migrate.stemWord(ingred)[0] for ingred in ingreds + search.defaultArr]
|
ingreds = [migrate.stemWord(ingred)[0] for ingred in ingreds + search.defaultArr]
|
||||||
end = time.time()
|
|
||||||
print("stem", end - start, "\n")
|
|
||||||
|
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
indx = search.fastes(ingreds)
|
indx = search.fastes(ingreds)
|
||||||
|
|
@ -34,7 +30,10 @@ class RecipeList(Resource):
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print("calc overlay",end - start, "\n")
|
print("calc overlay",end - start, "\n")
|
||||||
|
|
||||||
|
|
||||||
return flask.make_response(flask.jsonify({'data': recs}), 200)
|
return flask.make_response(flask.jsonify({'data': recs}), 200)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("error: -", e)
|
||||||
|
return flask.make_response(flask.jsonify({'error': str(e)}), 400)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,14 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
.recipe-name{
|
.recipe-name{
|
||||||
|
margin: 1rem 0;
|
||||||
}
|
}
|
||||||
.recipe-instructions{
|
.recipe-instructions{
|
||||||
display: grid;
|
display: grid;
|
||||||
width:70%;
|
width:70%;
|
||||||
}
|
}
|
||||||
.recipe-score{
|
.recipe-score{
|
||||||
|
margin: 1rem 1rem;
|
||||||
}
|
}
|
||||||
.recipe-container{
|
.recipe-container{
|
||||||
padding:0;
|
padding:0;
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,43 @@
|
||||||
|
|
||||||
var rl = document.getElementById("recipe-list")
|
var rl
|
||||||
|
|
||||||
function loadData() {
|
function loadData() {
|
||||||
rl = document.getElementById("recipe-list")
|
rl = document.getElementById("recipe-list")
|
||||||
|
// make string of get params for request
|
||||||
|
getParams = makeGetParamString()
|
||||||
|
|
||||||
|
getJSON("/api/v1/recipe/" + getParams,
|
||||||
|
function (error, data) {
|
||||||
|
data = data["data"] // remove wrapper
|
||||||
|
console.log(data)
|
||||||
|
renderRecipeList(data)
|
||||||
|
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeGetParamString(){
|
||||||
searchString = document.getElementById("search-field").value
|
searchString = document.getElementById("search-field").value
|
||||||
searchArray = searchString.split(',');
|
searchArray = searchString.split(',');
|
||||||
getParams = ""
|
getParams = ""
|
||||||
searchArray.forEach(
|
searchArray.forEach(
|
||||||
function (item, index) {
|
function (item, index) {
|
||||||
|
if(item.trim() !== ""){
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
getParams += "&ingred=" + item.trim()
|
getParams += "&ingred=" + item.trim()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getParams += "?ingred=" + item.trim()
|
getParams += "?ingred=" + item.trim()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log(getParams)
|
return getParams
|
||||||
getJSON("/api/v1/recipe/" + getParams,
|
}
|
||||||
function (error, data) {
|
|
||||||
data = data["data"] // remove wrapper
|
function renderRecipeList(data){
|
||||||
console.log(data)
|
let keys = Object.keys(data).reverse(); // iterate in reverse order, highest score up top
|
||||||
let keys = Object.keys(data).reverse();
|
|
||||||
rl.innerHTML = ""
|
rl.innerHTML = ""
|
||||||
keys.forEach(
|
keys.forEach(
|
||||||
function (key) {
|
function (key) {
|
||||||
|
|
@ -39,7 +55,7 @@ function loadData() {
|
||||||
<div class="card-body recipe-container">
|
<div class="card-body recipe-container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<img class="recipe-img" src="https://images.lecker.de/,id=091149c4,b=lecker,w=610,cg=c.jpg">
|
<img class="recipe-img" src="data:image/png;base64,${data1[4]}">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-7">
|
<div class="col-7">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -65,8 +81,4 @@ function loadData() {
|
||||||
`
|
`
|
||||||
rl.innerHTML += recString
|
rl.innerHTML += recString
|
||||||
})
|
})
|
||||||
},
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,6 @@ flask_restful
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
requests
|
requests
|
||||||
flask-restful-swagger-3
|
flask-restful-swagger-3
|
||||||
|
mysqlclient
|
||||||
|
nltk
|
||||||
|
opencv-python
|
||||||
|
|
|
||||||
4
run.py
4
run.py
|
|
@ -1,4 +1,8 @@
|
||||||
from application import app
|
from application import app
|
||||||
|
import nltk
|
||||||
|
|
||||||
|
nltk.download('stopwords')
|
||||||
|
nltk.download('punkt')
|
||||||
|
|
||||||
app.run(host="0.0.0.0", port='5001', debug=True, threaded=True)
|
app.run(host="0.0.0.0", port='5001', debug=True, threaded=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ def getRecDict(indx, inputArr):
|
||||||
for key in heapq.nlargest(10, outDict.keys()):
|
for key in heapq.nlargest(10, outDict.keys()):
|
||||||
key2 = outDict[key]
|
key2 = outDict[key]
|
||||||
rec = dbSession.query(Recipe).filter(Recipe.recipe_id==key2).first()
|
rec = dbSession.query(Recipe).filter(Recipe.recipe_id==key2).first()
|
||||||
outDict2[key] = (key2, rec.name, rec.url, [r[0] + ": " + r[1] for r in dbSession.query(Ingredient.name, Ingredient.ingredient_amount).filter(Ingredient.recipe_id==key2).all()])
|
outDict2[key] = (key2, rec.name, rec.url, [r[0] + ": " + r[1] for r in dbSession.query(Ingredient.name, Ingredient.ingredient_amount).filter(Ingredient.recipe_id==key2).all()], rec.img.decode('utf-8'))
|
||||||
return outDict2
|
return outDict2
|
||||||
|
|
||||||
def printDict(indx, inputArr):
|
def printDict(indx, inputArr):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue