def simple_search_recipe(app_session, question):
    search_type = command_input(
        bcolors.BOLD + "How would you like to search?" + bcolors.ENDC,
        ["By Ingredient", "By Name", "By Category", "Exit"])
    if search_type == "Exit":
        return None  # notify main to exit program

    sort_type = command_input(
        bcolors.BOLD + "How would you like to sort the search?" + bcolors.ENDC,
        ["Name", "Rating", "Recent", "Exit"])
    if sort_type == "Exit":
        return None  # notify to exit program

    command = input("Search Now: ")
    if command == "Exit":
        return None  # notify to exit program

    recipe_list = search_get_results(app_session, command, search_type,
                                     sort_type)

    if recipe_list == None:  # if no recipes, return to cook menu
        print(bcolors.FAIL + "No Recipes Found." + bcolors.ENDC)
        return None

    # pick a recipe from the search criteria
    print(question + " (Or Type \"Exit\" to leave this menu)")
    command = command_input(
        bcolors.BOLD + "Which Recipe?" + bcolors.ENDC,
        list(str(x) for x in range(0, recipe_list.count())) + ["Exit"])

    if command == "Exit":
        return None

    return recipe_list[int(command)]
def search(app_session):
    print(bcolors.HEADER + "Search for Recipe" + bcolors.ENDC)
    command = ""

    while command != "Exit":
        search_type = command_input(
            bcolors.BOLD + "How would you like to search?" + bcolors.ENDC,
            ["By Ingredient", "By Name", "By Category", "Exit"])
        if search_type == "Exit":
            break

        sort_type = command_input(
            bcolors.BOLD + "How would you like to sort the search?" +
            bcolors.ENDC, ["Name", "Rating", "Recent", "Exit"])
        if sort_type == "Exit":
            break

        command = input("Search Now: ")
        if command == "Exit":
            break

        search_get_results(app_session, command, search_type, sort_type)

    print(bcolors.OKBLUE + "Exiting Recipe Search" + bcolors.ENDC)
    return
Пример #3
0
def delete(app_session):
    recipes = get_users_recipes(app_session)

    print(bcolors.BOLD + bcolors.UNDERLINE + "Delete a Recipe" + bcolors.ENDC)
    print(
        "Please Enter the Number of the Recipe you Would Like to Delete. (Or Type \"exit\" to leave this menu"
    )

    for idx, r in enumerate(recipes):
        print(bcolors.BOLD + str(idx) + bcolors.ENDC + '.' + " " + r.name)

    number = command_input(
        bcolors.BOLD + "Which Recipe?" + bcolors.ENDC,
        list(str(x) for x in range(0, len(recipes))) + ["Exit"])

    if number == "Exit":
        return

    command = command_input(bcolors.BOLD + "Are you sure?" + bcolors.ENDC,
                            ["Yes", "No"])

    if command == "Yes":
        app_session.session.delete(recipes[int(number)])
        app_session.session.commit()
        print(bcolors.OKCYAN + "Successfully Deleted" + bcolors.ENDC)
Пример #4
0
def edit_steps(app_session, recipe):
    command = ""

    while command != "Exit":
        print_recipe_steps(recipe)
        command = command_input(
            bcolors.BOLD +
            "What would you like todo?\n1. Edit A Step\n2. Add a new step\n3. "
            "Delete a Step\n" + bcolors.ENDC, ["1", "2", "3", "4", "Exit"])

        if command == "1":
            command = command_input(
                bcolors.BOLD + "What step would you like to edit?" +
                bcolors.ENDC,
                [str(s.step_nr) for s in recipe.Steps] + ["Exit"])
            if command != "Exit":
                update_recipe_step(recipe.Steps[int(command) - 1], app_session)
                app_session.session.commit()

        elif command == "2":
            step = Step(step_nr=len(recipe.Steps) + 1)
            recipe.Steps.append(step)
            update_recipe_step(step, app_session)
            app_session.session.commit()

        elif command == "3":
            command = command_input(
                bcolors.BOLD + "Which step would you like to delete?" +
                bcolors.ENDC,
                [str(s.step_nr) for s in recipe.Steps] + ["Exit"])

            if command != "Exit":
                recipe.Steps.remove(recipe.Steps[int(command) - 1])
                app_session.session.commit()
Пример #5
0
def edit(app_session):
    recipes = get_users_recipes(app_session)

    print(bcolors.BOLD + bcolors.UNDERLINE + "Edit a Recipe" + bcolors.ENDC)
    print(
        "Please Enter the Number of the Recipe you Would Like to Edit. (Or Type \"exit\" to leave this menu"
    )

    for idx, r in enumerate(recipes):
        print(bcolors.BOLD + str(idx) + bcolors.ENDC + '.' + " " + r.name)

    command = command_input(
        bcolors.BOLD + "Which Recipe?" + bcolors.ENDC,
        list(str(x) for x in range(0, len(recipes))) + ["Exit"])

    if command == "Exit":
        return

    recipe = recipes[int(command)]
    pretty_print_recipe(recipe)

    options = {
        "Info": edit_info,
        "Steps": edit_steps,
        "Ingredients": edit_ingredients
    }
    command = ""
    while command != "Exit":
        command = command_input(
            bcolors.BOLD + "What would you like edit?" + bcolors.ENDC,
            ["Info", "Steps", "Ingredients", "Exit"])
        if command != "Exit":
            options[command](app_session, recipe)
Пример #6
0
def edit_ingredients(app_session, recipe):
    command = ""
    while command != "Exit":
        print_recipe_ingredients(recipe)
        command = command_input(
            bcolors.BOLD +
            "What would you like todo?\n1. Update an Amount\n2. "
            "Add an Ingredient\n3. Remove an Ingredient\n" + bcolors.ENDC,
            ["1", "2", "3", "Exit"])

        if command == "1":
            command = command_input(
                bcolors.BOLD + "What ingredient would you like to edit?" +
                bcolors.ENDC,
                [str(idx)
                 for idx, i in enumerate(recipe.Ingredients)] + ["Exit"])
            if command != "Exit":
                update_ingredient_amount(recipe.Ingredients[int(command)],
                                         app_session)

        elif command == "2":  # Add an Ingredient

            command = ""
            newSearch = True
            ingredients = []
            while newSearch:
                ingredients = print_ingredient_list_from_search(
                    input(bcolors.BOLD + "Search for an Ingredient: " +
                          bcolors.ENDC), app_session)

                command = command_input(
                    bcolors.BOLD + "Which ingredient would you like?" +
                    bcolors.ENDC,
                    [str(idx) for idx, i in enumerate(ingredients)] +
                    ["New Search", "Exit"])
                newSearch = (command == "New Search")

            if command == "Exit":
                break

            ingred = RecipeIngredients(Ingredient=ingredients[int(command)])
            recipe.Ingredients.append(ingred)
            update_ingredient_amount(ingred, app_session)
            app_session.session.commit()

        elif command == "3":
            command = command_input(
                bcolors.BOLD + "What ingredient would you like to delete?" +
                bcolors.ENDC,
                [str(idx)
                 for idx, i in enumerate(recipe.Ingredients)] + ["Exit"])

            if command != "Exit":
                app_session.session.delete(recipe.Ingredients[int(command)])
                app_session.session.commit()
Пример #7
0
def categorize(app_session):
    print(bcolors.BOLD + bcolors.UNDERLINE + "Categorize a Recipe" +
          bcolors.ENDC)  # header

    recipe = simple_search_recipe(
        app_session,
        "Please Enter the Number of the Recipe you Would Like to Categorize.")
    if recipe == None:
        return  # this means that there's nothing to categorize

    print(bcolors.UNDERLINE + "Category Editor" + bcolors.ENDC)
    command = ""
    while command != "Exit":
        command = command_input(
            "Would you like to change this recipe's categories or add a new one?",
            ["Remove", "Add", "View", "Exit"])
        if command == "Exit":
            return
        if command == "Remove":
            remove_category(app_session, recipe)
        if command == "Add":
            add_category(app_session, recipe)
        if command == "View":
            print_recipe_categories(recipe)

    return
def view_cooked(app_session):
    print(bcolors.BOLD + bcolors.UNDERLINE + "View Cooked Recipes" +
          bcolors.ENDC)

    # get cooked recipes
    cooked = app_session.session.query(Recipe.name, CookedBy.scale, CookedBy.cook_date, CookedBy.rating) \
        .filter(CookedBy.user_id == app_session.user.id) \
        .filter(Recipe.id == CookedBy.recipe_id).order_by(CookedBy.cook_date.desc())

    # print each recipe and its data
    idc = 1
    for name, scale, date, rating in cooked:
        # print the metadata
        print(bcolors.BOLD + name + bcolors.ENDC)
        print('\t' + bcolors.BOLD + "Scale: " + bcolors.ENDC + str(scale))
        print('\t' + bcolors.BOLD + "Date Cooked: " + bcolors.ENDC + str(date))
        print('\t' + bcolors.BOLD + "Rating:" + +bcolors.ENDC + str(rating))
        # Limit the number of responses shown
        if idc % 10 == 0:
            command = command_input(bcolors.OKGREEN + "Keep going?",
                                    ["Yes", "Exit"])
            if command == "Exit":
                return
        idc += 1

    return
def reduce(app_session):
    pantry = get_users_pantry(app_session)
    print(pantry)

    print(
        bcolors.BOLD + "Please enter the number of the ingredient you want to reduce. "
                       "Type \"Exit\" to close the Pantry Manager.")
    command = ""
    for idx, r in enumerate(pantry):
        print(bcolors.BOLD + str(idx) + bcolors.ENDC + '.' + " " + str(r.ingredient.name))
    while command != "Exit":
        command = command_input(
            bcolors.BOLD + "Select the ingredient you want to reduce. Type \"Exit\" to leave this menu."
            + bcolors.ENDC, list(str(x) for x in range(0, len(pantry))) + ["Exit"])
        if command != "Exit":
            p = pantry[int(command)]
            print(bcolors.BOLD + "Current quantity of " + str(p.ingredient.name) + ": " + bcolors.ENDC
                  + str(p.current_quantity))
            reduction = get_reduction()
            if reduction == float():                        # exit to pantry menu
                return
            if reduce_quantity_of_item(app_session, p.ingredient_id, reduction):
                print(bcolors.BOLD + "New quantity of " + str(p.ingredient.name) + ": " + bcolors.ENDC
                      + str(p.current_quantity))
            else:
                print(bcolors.FAIL + "Reduction failed." + bcolors.ENDC)
    return
def add(app_session):
    pantry = get_users_pantry(app_session)

    print(bcolors.BOLD + bcolors.OKCYAN + "Add ingredient(s)" + bcolors.ENDC)

    command = ""
    newSearch = True
    ingredients = []
    while newSearch:
        ingredients = print_ingredient_list_from_search(
            input(bcolors.BOLD + "Search for an Ingredient: " + bcolors.ENDC), app_session)

        command = command_input(bcolors.BOLD + "Which ingredient would you like?" +
                                bcolors.ENDC, [str(idx) for idx, i in enumerate(ingredients)] +
                                ["New Search", "Exit"])
        newSearch = (command == "New Search")

    purchase_date = input("Purchase Date (MM/DD/YYYY): ")
    expiration_date = input("Expiration Date (MM/DD/YYYY): ")
    quantity_bought = input('Quantity Bought: ')

    new_ingredient = UserPantry(ingredient_id=ingredients[int(command)].id, expiration_date=expiration_date,
                                purchase_date=purchase_date, quantity_bought=float(quantity_bought), current_quantity=float(quantity_bought))
    app_session.user.Pantry.append(new_ingredient)
    app_session.session.commit()

    print(bcolors.OKGREEN + "Successfully Added!" + bcolors.ENDC)
Пример #11
0
def remove_category(app_session, recipe):
    print_recipe_categories(recipe)
    category = command_input(
        bcolors.BOLD + "Which category will you remove?" + bcolors.ENDC,
        list(str(x) for x in range(0, len(recipe.Categories))) + ["Exit"])

    if category == "Exit":
        return

    confirmation = command_input(bcolors.BOLD + "Are you sure?" + bcolors.ENDC,
                                 ["Yes", "No"])

    if confirmation == "Yes":
        app_session.session.delete(recipe.Categories[int(category)])
        app_session.session.commit()
        print(bcolors.OKCYAN + "Successfully Deleted" + bcolors.ENDC)

    return
Пример #12
0
def authenticate(session):
    login_or_register = command_input(
        bcolors.BOLD + "Would you like to Login or Register?" + bcolors.ENDC,
        ["Login", "Register"])

    if login_or_register == "Register":
        registerInput(session)
        print("Please Login!")

    return ApplicationSession(session, loginInput(session))
def pantry(app_session):
    command = ""
    print(bcolors.HEADER + "Update Your Pantry" + bcolors.ENDC)
    while command != "Exit":
        command = command_input(bcolors.BOLD + "What do you want to do with your pantry?" + bcolors.ENDC,
                                ["add", "remove", "reduce", "view", "Exit"])
        if command == "add":
            add(app_session)
        if command == "remove":
            remove(app_session)
        if command == "reduce":
            reduce(app_session)
        if command == "view":
            view(app_session)
Пример #14
0
def cook(app_session):
    # os.system('clear')    # clear console window
    command = ""
    print(bcolors.HEADER + "Recipe Cooking Station" + bcolors.ENDC)
    while command != "Exit":
        command = command_input(
            bcolors.BOLD + "What would you like to do?" + bcolors.ENDC,
            ["Cook", "View Cooked Recipes", "Exit"])

        if command == "Cook":
            make_recipe(app_session)
        if command == "View Cooked Recipes":
            view_cooked(app_session)

    print(bcolors.OKBLUE + "Exiting Recipe Cooker" + bcolors.ENDC)
    return
Пример #15
0
def make_recipe(app_session):
    print(bcolors.BOLD + bcolors.UNDERLINE + "Cook a Recipe" +
          bcolors.ENDC)  # header
    # recipe_list = app_session.session.query(Recipe).filter(Recipe.id == 4020)

    # get the recipe from a search
    recipe = simple_search_recipe(
        app_session,
        "Please Enter the Number of the Recipe you Would Like to Cook.")
    if recipe == None:
        return

    # get the scale from user input
    scale = get_scale()
    if scale == float():  # or leave if they wanted to exit
        return

    # get the quantity of each item
    ingr_list = get_quantity(app_session, recipe, scale)
    if not ingr_list:
        print(bcolors.FAIL +
              "RECIPE FAILED. No ingredients are listed for this recipe." +
              bcolors.ENDC)
        return
    if type(ingr_list[0]) == str:
        print(bcolors.FAIL + "RECIPE FAILED. Needs " + str(ingr_list[1]) +
              " more " + ingr_list[0] + "." + bcolors.ENDC)
        return

    # rate the dish
    print(bcolors.OKGREEN + "You just cooked: " + recipe.name + "!" +
          bcolors.ENDC)
    command = command_input(
        bcolors.BOLD + "On a scale from 1 to 5, how was this dish?" +
        bcolors.ENDC, ['1', '2', '3', '4', '5'])

    # mark this moment down in history
    add_cooked_by(app_session, recipe, int(command), scale)

    # since all ingredients are guaranteed to be there, make the changes
    for ingr, amount in ingr_list:
        if not reduce_quantity_of_item(app_session, ingr, amount):
            return

    return
Пример #16
0
def RecipeController(app_session):
    command = ""
    print(bcolors.HEADER + "Recipe Editor" + bcolors.ENDC)
    while command != "Exit":
        command = command_input(
            bcolors.BOLD + "What would you like todo?" + bcolors.ENDC,
            ["Create", "Edit", "Delete", "Categorize", "Exit"])

        if command == "Edit":
            edit(app_session)
        if command == "Create":
            create(app_session)
        if command == "Delete":
            delete(app_session)
        if command == "Categorize":
            categorize(app_session)

    print(bcolors.OKBLUE + "Exiting Recipe Editor" + bcolors.ENDC)
Пример #17
0
def edit_info(app_session, recipe):
    print_recipe_metadata(recipe)

    command = ""
    while command != "Exit":
        command = command_input(
            bcolors.BOLD +
            "Which Piece of Information Would You Like to Edit?" +
            bcolors.ENDC, [
                "Name", "Description", "Difficulty", "Servings", "Cook Time",
                "Exit"
            ])
        update_recipe_info(command, recipe, app_session)
        app_session.session.commit()
        print_recipe_metadata(recipe)

    if command == "Exit":
        return
Пример #18
0
def functionality_flow(app_session):
    command = command_input(
        bcolors.BOLD + "What would you like todo?" + bcolors.ENDC, [
            "Search", "Cook", "RecipeEditor", "Pantry", "Recommendation",
            "Logout"
        ])

    # Emulate a Switch Statement
    options = {
        "Search": search,
        "Cook": cook,
        "RecipeEditor": RecipeController,
        "Pantry": pantry,
        "Recommendation": RecommendationController
    }
    if command == "Logout":
        app_session.logout = True
    else:
        options[command](app_session)
def remove(app_session):
    pantry = get_users_pantry(app_session)
    print(pantry)

    print(
        bcolors.BOLD + "Please enter the number of the ingredient you want to remove. "
                       "Type \"exit\" to close the Pantry Manager.")
    command = ""
    for idx, r in enumerate(pantry):
        print(bcolors.BOLD + str(idx) + bcolors.ENDC + '.' + " " + str(r.ingredient.name))
    command = command_input(
        bcolors.BOLD + "Select the ingredient you want to remove (or type exit to leave this menu)" + bcolors.ENDC,
        ["exit"])
    if command == "exit":
        return

    if command != "exit":
        app_session.session.delete(pantry[int(command)])
        app_session.session.commit()
        print(bcolors.OKCYAN + "Successfully Deleted" + bcolors.ENDC)
Пример #20
0
def update_recipe_info(infoName, recipe, app_session):
    if infoName == "Name":
        newName = input(bcolors.BOLD + "Enter the new name for the recipe: " +
                        bcolors.ENDC)
        recipe.name = newName
        print(bcolors.OKGREEN + "Change Successful" + bcolors.ENDC)
    elif infoName == "Description":
        description = input(bcolors.BOLD +
                            "Enter the new description for the recipe: " +
                            bcolors.ENDC)
        recipe.description = description
        print(bcolors.OKGREEN + "Change Successful" + bcolors.ENDC)
    elif infoName == "Cook Time":
        cookTime = input(bcolors.BOLD +
                         "Enter the new description for the recipe: " +
                         bcolors.ENDC)
        recipe.cook_time = int(cookTime)
        print(bcolors.OKGREEN + "Change Successful" + bcolors.ENDC)
    elif infoName == "Servings":
        servings = input(bcolors.BOLD +
                         "Enter the new description for the recipe: " +
                         bcolors.ENDC)
        recipe.servings = int(servings)
        print(bcolors.OKGREEN + "Change Successful" + bcolors.ENDC)
    elif infoName == "Difficulty":
        command = command_input(
            "Enter the new Difficulty for the recipe: ",
            ['easy', 'easy_medium', 'medium', 'medium_hard', 'hard'])
        if command == "easy":
            recipe.difficulty = DifficultyEnum.easy
        elif command == "easy_medium":
            recipe.difficulty = DifficultyEnum.easy_medium
        elif command == "medium":
            recipe.difficulty = DifficultyEnum.medium
        elif command == "medium_hard":
            recipe.difficulty = DifficultyEnum.medium_hard
        elif command == "hard":
            recipe.difficulty = DifficultyEnum.hard
        print(bcolors.OKGREEN + "Change Successful" + bcolors.ENDC)