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
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
def get_all_foods(self): """returns a list of all food items in the db""" with self.conn: self.c.execute("SELECT * FROM fooditems") all_foods = self.c.fetchall() food_items = [] for info_list in all_foods: food = FoodItem() food.set_info_from_list(info_list) food_items.append(food) return food_items
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
def get_update_info(): prompts = ('name', 'ss', 'unit', 'cal', 'carb', 'fat', 'protein', 'fiber', 'sugar') info = [] updated_food = FoodItem() answer = '' i = 0 while answer != 'x' and i < 9: answer = input(f"Enter {prompts[i]}: ") if answer.lower() == 'x': return None if prompts[i] == 'name': food_by_name = food_dao.get_foods_by_name(answer) if food_by_name is None: print(f"\nNo results found for {answer}") return None info.append(answer) i += 1 updated_food.set_info_from_list(info) return updated_food
def setUp(self): self.banana = FoodItem('banana') banana_nutrition = { 'calories': 110, 'total_fat': 0, 'sat_fat': 0, 'poly_fat': 0, 'mono_fat': 0, 'trans_fat': 0, 'cholesterol': 0, 'sodium': 0, 'potassium': 450, 'total_carbs': 29, 'dietary_fiber': 3, 'sugars': 15, 'protein': 1, 'vitamin_a': 2, 'vitamin_c': 20, 'calcium': 0, 'iron': 2 } self.banana.set_nutrition(banana_nutrition)
def setUp(self): self.food_1 = FoodItem('apple', '50', 'g', '100', '20', '1', '2', '3', '10') self.food_2 = FoodItem('oats', '40', 'g', '120', '25', '3', '5', '6', '1')
def insert_food(food_info): food = FoodItem() food.set_info_from_list(food_info) food_dao.insert_food(food)
from fooditem import FoodItem from dao import DAO from macros import calc_macros import text_user_interface as tui from meal import Meal tui.run() food_dao = DAO() oats = FoodItem('oats', '40', 'g', '150', '25', '4', '4', '4', '2') banana = FoodItem('banana', '1', 'banana', '75', '12', '0', '1', '1', '8') #print(oats) #print(banana) #breakfast = Meal() #breakfast.add_ingredient(oats, 100) #breakfast.add_ingredient(banana, 0.5) #print(breakfast) #breakfast.calc_meal_macros() breakfast = Meal() breakfast.add_ingredient(oats, 125) #print(breakfast) #print(breakfast.get_ingredients()) #oats.proportionalize(125)