def find_recipes():
    """
    Gets data about food from API
    """
    while True:
        try:
            min_calories, max_calories = map(int, input('Please enter minimum'+\
            ' and maximum calories separated by space: ').split())
            break
        except:
            print('Invalid format, please enter again')
    ingred = input('Please enter prefered ingredients, leave blank to'+\
    ' search without selected ingredient:')
    if ingred == '':
        ingred = None
    filename = f'resources{max_calories}-{min_calories}.txt'
    try:
        assert os.path.exists(os.path.dirname(filename))
        recipes = parse_information(file)
    except:
        file = get_data(max_calories, min_calories, ingred)
        recipes = parse_information(file)
    recipebook = []
    for el in recipes:
        ingredients = {}
        for ingr in el[2]:
            ingredients[Ingredient(ingr[0],ingr[3]['Calories'],ingr[3]\
                ['Carbohydrates'],ingr[3]['Protein'],ingr[3]['Fat'],set())]\
                = (ingr[1], ingr[2])
        recipebook.append(Recipe(el[0],el[1]['Calories'],el[1]['Carbohydrates'],el[1]\
            ['Protein'],el[1]['Fat'],ingredients,el[3]))
        for ingr in ingredients:
            ingr.add_recipe(recipebook[-1])
    return recipebook
Beispiel #2
0
def ingredient_from_set(file_list, ingredient_names, amount=False):
    """Returns an ingredient from the inspiring set.A boolean is sent in the parameter to determine if we also need to change the ingredients amount"""
    # Finds the random file
    if (len(file_list) == 1):
        afile = file_list[0]
    else:
        afile = file_list[random.randint(0, (len(file_list) - 1))]

    # This while loop ensures that the chosen ingredient from the i
    # nspiring set does not match an ingredient in the curent
    # list of ingredients
    while (True):
        # Chooses a random line from the random file
        lines = open(afile).read().splitlines()
        my_line = random.choice(lines)
        print(my_line)
        # ingredient_name = my_line.split(' g ')[1]
        if (my_line.find(" g ") != -1):
            ingredient_name = my_line.split(' g ')[1]
            ingredient_amount = my_line.split()[0]
        else:
            ingredient_name = " ".join(my_line.split()[1:])

        if (ingredient_names.count(ingredient_name) == 0):
            if (amount):
                return Ingredient(ingredient_name, ingredient_amount)
            else:
                return ingredient_name
Beispiel #3
0
def create_ingredients(name, measurement, dict_ing_of_value):
    """Returns the new Ingredient object."""
    ingredient_created = Ingredient(name, measurement)

    # Add ingredient to INGREDIENTS_OF_VALUE
    if ingredient_created.name in dict_ing_of_value:
        dict_ing_of_value[ingredient_created.name] = dict_ing_of_value[
            ingredient_created.name] + [ingredient_created.amount]
    else:
        dict_ing_of_value[ingredient_created.name] = [
            ingredient_created.amount
        ]

    ingredient_created.update_value(dict_ing_of_value)

    return ingredient_created
Beispiel #4
0
def add_ingredient(recipe_obj, file_list):
    """An ingredient is selected uniformly at random from the inspiring set 
    and added to the recipe."""
    ingredient_name = ingredient_from_set(file_list, recipe_obj.ingredients)

    # The amount of the new ingredient will be an int ,i, such that
    # 1<=1<10
    ingredient_amount = random.randrange(1, 10)
    recipe_obj.ingredients.append(
        Ingredient(ingredient_name, ingredient_amount))
Beispiel #5
0
from pint import UnitRegistry, quantity
from datetime import datetime

from classes import Ingredient, Dish, MenuItem, NameDict

units = UnitRegistry()

participants = float(35)
vegetarians = float(7)
carnivores = participants - vegetarians
carnivoreshare = float(carnivores) / float(participants)

ingredient_types = NameDict([
    Ingredient(name=u"Oliver, svarta",
               purchase_unit=units.kilograms,
               category=u"burk",
               conversions=[657 * units.kilograms / units.meter**3]),
    Ingredient(name=u"Olja, oliv", purchase_unit=units.liter,
               category=u"burk"),
    Ingredient(name=u"Olja, raps", purchase_unit=units.liter,
               category=u"burk"),
    Ingredient(name=u"Krossade tomater",
               purchase_unit=units.kilograms,
               category=u"burk"),
    Ingredient(name=u"Matlagningsvin, vitt",
               purchase_unit=units.litres,
               category=u"burk"),
    Ingredient(name=u"Tomatpuré",
               purchase_unit=units.kilograms,
               category=u"burk",
               conversions=[130 * units.grams / (units.deciliters)]),
def create_ingredients(name, measurement):
    """Returns the new Ingredient object."""
    ingredient_created = Ingredient(name, measurement)
    return ingredient_created