Beispiel #1
0
def random_meal(categories):
    random_category_value = randint(0, len(categories))
    random_category = categories[random_category_value].get_category()
    meals = requests.get_meals_by_category(random_category)
    random_meal_value = randint(0, len(meals))
    random_meal = meals[random_meal_value].get_meal()
    meal = requests.get_meal_by_name(random_meal)
    display_meal(meal)
Beispiel #2
0
def search_meal_by_name():
    print()
    lookup_meal = input("Enter Meal Name: ")
    print()
    meal = requests.get_meal_by_name(lookup_meal)
    if meal:
        display_meal(meal)
    else:
        print("A recipe for this meal was not found")
Beispiel #3
0
def display_random_recipe():
    """
        This method is used to get a random meal and display its
        recipe and ingredients
    """
    random_name = requests.get_random_meal()
    random_meal = requests.get_meal_by_name(random_name)
    display_recipe(random_meal)
    display_ingredients(random_name)
def search_meal_by_name():
    """
        This method is used to get a meals name from the user and
        make the call to get the meal from the site
    """
    lookup_meal = input("Enter Meal Name: ")

    meal = requests.get_meal_by_name(lookup_meal)
    if meal:
        display_meal(meal)
    else:
        print("A recipe for this meal was not found.\n")
Beispiel #5
0
def get_recipe_str(recipe, meal_str):
    """
        This method searches for the recipe of the entered meal. If found, will
        return a string with the meal's recipe and ingredients already formatted.
        If not found, will return a string with the appropriate message
    """

    recipe_object = requests.get_meal_by_name(meal_str)
    if recipe_object:
        recipe += "Recipe: " + recipe_object.get_meal() + "\n\n"
        my_wrap = textwrap.TextWrapper(width=80)

        # Get and format the instructions
        wrap_list = my_wrap.wrap("Instructions: " +
                                 recipe_object.get_instructions())
        for line in wrap_list:
            recipe += line + "\n"

        # Get and format the ingredient/measurements
        ingredients = requests.get_ingredients_and_measurements(meal_str)
        formatting = "{:<30}"
        recipe += "\n\nIngredients:\n"
        recipe += "-" * 80 + "\n"

        try:
            for i in range(len(ingredients)):
                ingredient = ingredients[i]
                item = formatting.format(ingredient.get_measure() + " " +
                                         ingredient.get_ingredient())
                recipe += item + "\n"
        except TypeError:
            recipe = "Error in ingredient format. Try another recipe."

    else:
        recipe = "A recipe for this meal was not found."

    return recipe
Beispiel #6
0
    def load_meal(self, evt):
        """
            Populate the recipe listbox with the meals from the meals by category. Note the Try Except...
            Selecting text in the meal directions text box triggered this method and caused an
            "Index out of Range Error" crash when getting the index. This try Except handles the crash.
        """

        try:
            # Get the selected recipe from the recipe listbox
            index = int(self.meal_list_listbox.curselection()[0])

            # Get the recipe details
            meal_name = self.meal_list_listbox.get(index)
            meal = requests.get_meal_by_name(meal_name)

            # Clear the existing meal directions before the new one is added
            self.clear_meal()

            # Add the directions for the meal
            self.directions_text.config(state="normal")
            self.directions_text.insert(END, meal.get_instructions())
            self.directions_text.config(state="disabled")
        except IndexError:
            pass