Copy of Snippet "Task"

CaloriCo​:hamburger::hamburger:
---
Are you tired of guessing your daily calorie intake and struggling to maintain a healthy lifestyle? Say goodbye to uncertainty and hello to CaloriCo – your ultimate solution for tracking and managing your calories!
---

Daily Calories Limit(Kcal): {formtext: name=limit; default=2000}
User Name: {formtext: name=name; default=Abhishek}
Date: {time: YYYY-MM-DD}

{date={time: YYYY-MM-DD}}
{if: name=""}{error: Please enter a valid name}{endif}
{if: limit<1500}{error: The lowest value can be 1500\ }{endif}


Total Calories Today (kcal): {formtext: name=Total_Calories_Today; default=0}

Check food Item details
Food Item: {formtext: name=Food_Item; default=apple}
{note: preview=no}
{urlload: https://api.calorieninjas.com/v1/nutrition?query={=Food_Item}; method=GET; headers=X-Api-Key:RyKDI8c52NHQaXlqtxVqyw\=\=zmfaoffnPcGjV6sJ; done=(res)->["nutrition_data":res]}
{endnote}
{if: fromjson(nutrition_data).items = }{error: Please provide a valid food name }{endif}

Nutritional Information for {=Food_Item} :apple: :

{data=fromjson(nutrition_data).items[1]}
- :rice_cracker: Calories: {=data.calories} kcal  
- :hotdog: Carbohydrates: {=data.carbohydrates_total_g} g  
- :poultry_leg: Proteins: {=data.protein_g} g  
- :pancakes: Fats: {=data.fat_total_g} g  
- :rice_cracker: Sugar: {=data.sugar_g} g  
- :bowl_with_spoon:Serving Size: {=data.serving_size_g} g

{dbinsert: INSERT INTO Task SET Name = apple, Count = 1, Calories = 2, Carbohydrates = 3, Proteins = 4, Fats = 5, Sugar = 6
; space=2TEKO2uxraZ2gqemll0zfD; autoaddfields=yes; completed=(result,status)->"ERROR" if status<>200 else "Success" }
{dbinsert: INSERT INTO Task SET Name = {=Food_Item}, Count = 1, Calories = {=data.calories}, Carbohydrates = {=data.carbohydrates_total_g}, Proteins = {=data.protein_g}, Fats = {=data.fat_total_g}, Sugar = {=data.sugar_g}
; space=2TEKO2uxraZ2gqemll0zfD; autoaddfields=yes; completed=(result,status)->"ERROR" if status<>200 else "Success" }


{Total_Calories_Today={dbselect: SELECT sumagg(Calories) AS Calories, Date FROM Task WHERE Date = @date GROUP BY Date; space=2TEKO2uxraZ2gqemll0zfD; menu=no; multiple=no}}

{if: Total_Calories_Today > limit}{error: you reached your limit}{endif}

Data provided by CalorieNinjas API