def add_food(): data = request.json food = Food(data["id"], data["protein"], data["carbs"], data["fat"], data["servingSize"], data["servingType"]) if db.add(collection="foods", resource=food.to_dict()): return {"success": True}, 201 else: return {"success": False}, 500
def get_recipes_by_id(recipe_id): food = Food.find_one_food_by_id(recipe_id) ingredients = Ingredients.find_ingredients_by_food_id(recipe_id) return render_template('recipes_by_id.html', recipe_id=recipe_id, food=food, ingredients=ingredients)
def new(): name = request.form.get("name") kcal = request.form.get("kcal") co2 = request.form.get("co2") food = Food(name=name, kcal=kcal, co2=co2) try: session.add(food) session.commit() return jsonify({"response": "success"}) except Exception as err: return jsonify({"response": "error", "message": str(err)})
def new_recipe_save(): food_name = request.form['food_name'] food_category = request.form['category'] food_img = request.form['food_img'] food_prep = request.form['food_prep'] if Food.food_exists(food_name): return render_template('food_exists.html', name=food_name) if Types_Of_Food.type_exists(food_category): typef = Types_Of_Food.find_one_type(type=food_category) type_id = typef.get_id() else: typef = Types_Of_Food(type=food_category) typef.save_type() typef = Types_Of_Food.find_one_type(type=food_category) type_id = typef.get_id() food = Food(name=food_name, preparation=food_prep, type_id=type_id, img=food_img) food.save_food() food_id = food.get_id() return redirect(url_for('add_ingredient', food_id=food_id))
def test_new_food(): """ GIVEN a Food model WHEN a new food is created THEN check the name, protein, carbs, fat, serving_type fields are defined correctly """ food = Food( id="chicken", protein=53.4, carbs=0, fat=6.2, serving_size=172, serving_type="gram", ) assert math.isclose(food.protein, 0.3104651162790698) assert math.isclose(food.carbs, 0) assert math.isclose(food.fat, 0.036046511627907) assert food.serving_type == "gram" assert food.id == "chicken"
def add_ingredient(food_id): food = Food.find_one_food_by_id(food_id) food_name = food.name food_img = food.img food_type = Types_Of_Food.find_one_id(food.type_id) food_category = food_type.type food_prep = food.preparation ingredients_exist = Ingredients.find_ingredients_by_food_id(food.get_id()) ingredients_all = Ingredients.find_all_ingredients() return render_template('add_ingredients.html', food_id=food_id, food_name=food_name, food_img=food_img, food_category=food_category, food_prep=food_prep, ingredients_all=ingredients_all, ingredients_exist=ingredients_exist)
clockobject = pygame.time.Clock() clockobject.tick(200) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False #Reset screen screen.fill(255) #Time to refresh screen tick_timer += 1 #Generate Food if food_exists == False: apple = Food(20, screen, (255, 100, 100), random.randint(0, 39), random.randint(0, 39)) food_exists = True apple.draw() #Key input if event.type == pygame.KEYDOWN: if event.key == pygame.K_w and y != 1: (x, y) = (0, -1) if event.key == pygame.K_s and y != -1: (x, y) = (0, 1) if event.key == pygame.K_a and x != 1: (x, y) = (-1, 0) if event.key == pygame.K_d and x != -1: (x, y) = (1, 0) if tick_timer % 8 == 0:
def get_recipes_by_category(type_id): category = Types_Of_Food.find_one_id(type_id) foods = Food.find_foods_by_type(type_id) return render_template('recipes_by_type.html', foods=foods, category=category)
def recipes(): categories = Types_Of_Food.find_all_types() foods = Food.find_foods() return render_template('recipes.html', foods=foods, categories=categories)