Пример #1
0
def create_dummy_recipes():
    recipes = []
    for x in range(N_RECIPES):
        name = "".join(random.choices(string.ascii_lowercase, k=10))
        name = name.capitalize()  #macht den ersten buchstaben groß
        description = "".join(
            random.choices(
                string.ascii_lowercase + "   ",
                k=80))  # alle buchstaben des alphabets plus ein leerzeichen
        taste = "".join(random.choices(string.ascii_lowercase, k=5))
        new_recipe = model.Recipe(name=name,
                                  description=description,
                                  taste=taste)
        recipes.append(new_recipe)

    recipe_1 = model.Recipe(name="Apfelstrudel",
                            description="Cut Apple Bake Sweet",
                            taste="sweet dish")
    recipes.append(recipe_1)
    recipe_2 = model.Recipe(name="Hamburger",
                            description="Fry Meat and Eat",
                            taste="salty dish")
    recipes.append(recipe_2)
    recipe_3 = model.Recipe(name="Soup",
                            description="Cut Carrots, Add Water",
                            taste="salty dish")
    recipes.append(recipe_3)

    for recipe in recipes:
        if not db.query(model.Recipe).filter_by(name=recipe.name).first():
            db.add(recipe)
    db.commit()
Пример #2
0
def create_dummy_recipes():
    recipes = []
    for x in range(N_RECIPES):
        name = "".join(random.choices(string.ascii_lowercase, k=10))
        name = name.capitalize()
        description = "".join(random.choices(string.ascii_lowercase + "   ", k=80))
        taste = "".join(random.choices(string.ascii_lowercase, k=5))
        recipes.append(model.Recipe(name=name, description=description, taste=taste))

    recipe_1 = model.Recipe(name="Apfelstrudel", description="Cut Apple Bake Sweet", taste="sweet")
    recipes.append(recipe_1)
    recipe_2 = model.Recipe(name="Hamburger", description="Fry Meat And Eat", taste="salty")
    recipes.append(recipe_2)
    recipe_3 = model.Recipe(name="Suppe", description="Cut carrots Add Water", taste="sweet")
    recipes.append(recipe_3)

    for r in recipes:
        if not db.query(model.Recipe).filter_by(name=r.name).first():
            db.add(r)

    db.commit()
Пример #3
0
def get_recipe():
    with model.Database(DB) as rdb:
        result = rdb.select_recipe(recipe_id)
        recipe = model.Recipe(result[0], result[1], result[2], result[3], result[4])
    return jsonify(recipe.dictionary)
Пример #4
0
import re
from sqlalchemy.orm.exc import NoResultFound

recipe_filenames = os.listdir("./recipes")
ingredient_pattern = re.compile(u"([^A-Z]+)?([A-Z][^,]*)(?:, )?(.*)?")

model.db.drop_all()
model.db.create_all()

for fn in recipe_filenames:
    with open("./recipes/%s" % fn) as f:
        r_obj = json.load(f)

        r = model.Recipe(directions=r_obj["directions"],
                         cook_time=r_obj["cook_time"],
                         prep_time=r_obj["prep_time"],
                         serves=r_obj["serves"],
                         title=r_obj["title"],
                         id=fn)

        model.db.session.add(r)

        try:
            category = model.Category.query.filter_by(
                name=r_obj["category"]).one()
        except NoResultFound as e:
            category = model.Category(name=r_obj["category"])
            model.db.session.add(category)

        r.category = category

        for i in r_obj['ingredients']:
Пример #5
0
def addRecipe(userViewID):

    displayRecipes = showUserRecipeList(userViewID)
    recipe_name = request.form.get('recipename')
    notes = request.form.get('usercomments')

    dupe = model.session.query(model.Recipe)\
        .filter_by(recipe_name=recipe_name)\
        .filter_by(user_id=session["user_id"]).all()

    if dupe != []:
        flash("Duplicate Recipe Name")
        return redirect("/addRecipe/" + str(userViewID))

    newRecipe = model.Recipe()
    newRecipe.user_id = session["user_id"]
    newRecipe.recipe_name = recipe_name
    newRecipe.user_notes = notes

    displayRecipes.append(newRecipe)

    model.session.add(newRecipe)
    model.session.commit()

    batchComp = []
    batchsize = None
    chem_list = request.values.getlist("chem")
    percentages = request.values.getlist("percentage")
    i = 0
    for chem in chem_list:
        comp = model.Component()
        comp.chem_name = chem
        comp.chem_id = model.Chem.getChemIDByName(comp.chem_name)
        comp.percentage = float(percentages[i])
        i += 1
        comp.recipe_id = newRecipe.id
        batchComp.append(float(comp.percentage))
        model.session.add(comp)
        model.session.commit()

    kgchecked = 'checked = "checked"'
    lbschecked = ""
    unitSys = "kg"
    wholeNumList = []
    frctnList = []
    messageToUser = None

    components = model.Component.getComponentsByRecipeID(newRecipe.id)

    return render_template("recipecomps.html",
                           user_id=userViewID,
                           recipe_name=newRecipe.recipe_name,
                           components=components,
                           batchComp=batchComp,
                           batchsize=batchsize,
                           displayRecipes=displayRecipes,
                           user_notes=newRecipe.user_notes,
                           kgchecked=kgchecked,
                           lbschecked=lbschecked,
                           unitSys=unitSys,
                           wholeNumList=wholeNumList,
                           frctnList=frctnList,
                           messageToUser=messageToUser)
Пример #6
0
def enterRecipe():

    recipeName = request.form.get('recipename')
    batchsize = request.form.get('batchsize')

    newRecipe = model.Recipe()
    newRecipe.recipe_name = recipeName

    batchComp = []
    sizeflt = float(batchsize)
    kgchecked = 'checked = "checked"'
    lbschecked = ""
    unitSys = "kg"
    percent_list = []
    wholeNumList = []
    frctnList = []
    messageToUser = None

    chem_list = request.values.getlist('chem')
    percentages = request.values.getlist('percentage')
    if percentages == []:
        flash("no entry")
        return redirect("/enterRecipe")

    i = 0
    for chem in chem_list:
        comp = model.Component()
        comp.chem_name = chem
        comp.chem_id = model.Chem.getChemIDByName(comp.chem_name)
        comp.percentage = float(percentages[i])
        percent_list.append(comp.percentage)
        i += 1
        comp.recipe_id = newRecipe.id
        batchComp.append(float(comp.percentage))

    onehundred = converter.checkPercent(percent_list)
    newPercent = converter.getPercentMult(percent_list)

    if onehundred is False:
        messageToUser = "******"
    else:
        messageToUser = None

    for i in range(len(batchComp)):
        batchComp[i] = (sizeflt * batchComp[i]) * newPercent

        wholeNumList.append(int(batchComp[i]))
        if unitSys == "kg":
            frctnList.append(int(converter.frctnKilosToGrams(batchComp[i])))
            kgchecked = 'checked = "checked"'
        else:
            frctnList.append(int(converter.frctnPoundsToOunces(batchComp[i])))
            lbschecked = 'checked = "checked"'

    return render_template("calc_recipe.html",
                           recipe_name=newRecipe.recipe_name,
                           chem_list=chem_list,
                           percentages=percentages,
                           batchComp=batchComp,
                           batchsize=batchsize,
                           kgchecked=kgchecked,
                           lbschecked=lbschecked,
                           unitSys=unitSys,
                           wholeNumList=wholeNumList,
                           frctnList=frctnList,
                           messageToUser=messageToUser)