Exemplo n.º 1
0
def add_ingredient():
    json_data = flask.request.json

    # name
    name = json_data.get('name')
    if not name:
        return flask.jsonify({'msg': 'Must provide non-empty name'}), 400

    ingredient = Ingredient(name=name)
    if not ingredient.save():
        return flask.jsonify({'msg': 'Error in saving data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
Exemplo n.º 2
0
def edit_ingredient(ingredientId: str):
    json_data = flask.request.json
    ingredient = Ingredient.get_by_id(ingredientId)

    # name
    name = json_data.get('name')
    if name:
        ingredient.name = name

    if not ingredient.save():
        return flask.jsonify({'msg': 'Error in saving data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
Exemplo n.º 3
0
 def ingredients(self):
     from models.model_ingredient import Ingredient
     from models.relation_step_ingredient import StepIngredientRelation
     return Ingredient.select().join(
         StepIngredientRelation,
         pw.JOIN.LEFT_OUTER).where(StepIngredientRelation.step == self)
Exemplo n.º 4
0
def delete_ingredient(ingredientId: str):
    ingredient = Ingredient.get_by_id(ingredientId)
    if not ingredient.delete_instance():
        return flask.jsonify({'msg': 'Error in deleting data'}), 400
    return flask.jsonify({'msg': 'Success'}), 200
Exemplo n.º 5
0
def get_ingredient(ingredientId: str):
    ingredient = Ingredient.get_by_id(ingredientId)
    return flask.jsonify({'msg': 'Success', 'data': ingredient.as_dict()}), 200
Exemplo n.º 6
0
def get_ingredients():
    query = Ingredient.select()

    ingredients = [c for c in query]
    ingredient_dicts = [c.as_dict() for c in ingredients]
    return flask.jsonify({'msg': 'Success', 'data': ingredient_dicts}), 200
Exemplo n.º 7
0
 def wrapper(ingredientId, *args, **kwargs):
     ingredient = Ingredient.get_or_none(Ingredient.id == ingredientId)
     if ingredient:
         return func(ingredientId, *args, **kwargs)
     else:
         return flask.jsonify({'msg': 'Ingredient does not exists'}), 400
Exemplo n.º 8
0
# Step 3: Tags
tags_df = pd.read_csv("data/tags.csv", sep=';')
tags = []
tag_names = []
for tag_id, tag in tags_df.iterrows():
    tags.append(Tag(text=tag['text'].strip()))
    tag_names.append(tag['text'].strip().lower().replace(' ', ''))
Tag.bulk_create(tags)

# Step 4: Ingredients
ingredients_df = pd.read_csv("data/ingredients.csv", sep=';')
ingredients = []
ingredient_names = []
for ingredient_id, ingredient in ingredients_df.iterrows():
    ingredients.append(Ingredient(name=ingredient['name'].strip()))
    ingredient_names.append(ingredient['name'].strip().lower().replace(
        ' ', ''))

Ingredient.bulk_create(ingredients)

# Step 5: Recipes
with Path("data/recipes.txt").open('r') as f:
    lines = f.readlines()

recipes = []
recipe_ingredients = []
steps = []
recipe_tags = []
recipe_id = 0
step_no = 1