def saveRecipe(tokens, recipe):
    """
    Saves the recipe if it is fully filled in, otherwise gives an error message
    :param tokens: processed line of input
    :param recipe: recipe being saved
    :return:
    """
    ready = True
    if len(recipe.ingredients.keys()) == 0:
        print("Cannot save recipe with zero ingredients")
        ready = False
    if len(recipe.steps) == 0:
        print("Cannot save recipe with no steps")
        ready = False
    if( recipe.servings is None):
        print("Must set servings size of recipe before saving")
        ready = False
    if(recipe.time is None):
        print("Must set prep time of recipe before saving")
        ready = False

    if not ready:
        return
    #displayRecipe(recipe)
    if recipe.rid is not None:
        recipe.delete()

    Recipe.register_recipe(MANAGER, name=recipe.name, prep_time=recipe.time,
                           servings=recipe.servings, equipment=recipe.equipment,
                           owner=USER, steps=recipe.steps,
                           ingredients=recipe.ingredients)

    print(recipe.name + " saved successfully!")
    back(tokens)
Beispiel #2
0
def generate():
    adjectives = file_to_string_list(ADJECTIVES)
    food_genres = file_to_string_list(FOOD_GENRES)
    persons = file_to_string_list(PERSONS)
    pt_verbs = file_to_string_list(PT_VERBS)
    ingredients = list(map(lambda x: ingredient_from_st(x), file_to_string_list(INGREDIENTS)))

    addition_methods = file_to_string_list(ADDITION_METHODS)
    final_steps = file_to_string_list(FINAL_STEPS)

    for i in range(VOLUME):
        recipe_ingredients = random.sample(ingredients, k=random.randint(1, min(len(ingredients)-1, MAX_INGREDIENTS_PER_RECIPE)))

        title_ingredient = random.choice(recipe_ingredients)
        name = assemble_name(persons, adjectives, pt_verbs, title_ingredient, food_genres)

        equip_dictionary = readEquipment(EQUIPMENT)

        selected_equips = random.sample(list(equip_dictionary.keys()), k=random.randint(0, len(list(equip_dictionary.keys()))))

        selected_equips_dict = {}
        for eq in selected_equips:
            selected_equips_dict[eq] = equip_dictionary[eq]

        recipe_steps = gen_steps_lst(addition_methods, recipe_ingredients, selected_equips_dict, final_steps)

        ingredients_dict = gen_ingredient_dictionary(recipe_ingredients)

        rec = Recipe(MANAGER, 0, random.randint(1, 4), random.randint(5, 360), name, list(selected_equips_dict.keys()), None, ingredients_dict, recipe_steps)

        print("====================")
        displayRecipe(rec)

        Recipe.register_recipe(manager=MANAGER, name=name,
                               servings=random.randrange(1, 4),
                               time=random.randint(5, 360),
                               equip=list(selected_equips_dict.keys()),
                               owner=USER, ingr=ingredients_dict,
                               steps=recipe_steps, owner_id=USER.uid)