Ejemplo n.º 1
0
 def convert_to_food_items_list(self, fetched):
     foods_list = []
     for info_tuple in fetched:
         food = FoodItem()
         food.set_info_from_tuple(info_tuple)
         foods_list.append(food)
     return foods_list
Ejemplo n.º 2
0
 def get_foods_by_name(self, name):
     self.c.execute("SELECT * FROM fooditems WHERE name=?", (name,))
     food_info_tuple = self.c.fetchone()
     food = FoodItem()
     if food_info_tuple is None:
         return None
     food.set_info_from_tuple(food_info_tuple)
     return food
Ejemplo n.º 3
0
def calc_macros():
    food_dao = DAO()
    name = input("Enter name of food: ")
    if name == 'x':
        return None
    food_by_name = food_dao.get_foods_by_name(name)
    if food_by_name is None:
        print("No foods found")
        return None
    else:
        size = input("Enter amount: ")
        if size == 'x':
            return None
        ratio = float(size) / food_by_name.ss()
        print(f"ratio: {ratio}") # testing
        altered_food = FoodItem()
        altered_food.set_info_from_tuple(food_by_name.get_tuple())
        altered_food.proportionalize(ratio)
        return altered_food