Files
nutrihelper/main.py

69 lines
1.9 KiB
Python

import asyncio
import mealie_client
from usda_fdc_python.usda_fdc.analysis.recipe import (
create_recipe,
analyze_recipe)
from nutrihelper.utils import (
ingredientParser,
nutritionParser
)
import os
from dotenv import load_dotenv
async def main():
load_dotenv()
mealie_url = os.getenv("MEALIE_URL")
mealie_api_key = os.getenv("MEALIE_API_KEY")
fdc_api_key = os.getenv("FDC_API_KEY")
async with mealie_client.MealieClient(
base_url = mealie_url,
api_token = mealie_api_key
) as m_client:
recipe_id = "e733fc62-2dce-4fa0-98ba-f46ef75699ba" # fudgey brownies
# recipe_id = "bcbbf532-185f-41f4-876d-beaf7ff0fb32" # Greek orzo
recipe = await m_client.recipes.get(recipe_id)
if recipe:
fdc_client = FdcClient(fdc_api_key)
print(f"Recipe: {recipe.id}")
recipeIngredients = ingredientParser(recipe,fdc_client)
# print(f"r: {recipeIngredients}")
# print(f"Len: {len(recipeIngredients)}")
newRecipe = create_recipe(
name="Fudgey Brownies Test",
ingredient_texts = recipeIngredients,
client = fdc_client,
servings=9
)
# print(f"{newRecipe}")
# newIngredients = newRecipe.ingredients
# print(f"n: {newIngredients}")
# print(f"Len: {len(newIngredients)}")
#if len(newIngredients) != len(recipeIngredients):
analysis = analyze_recipe(newRecipe)
per_serving = analysis.per_serving_analysis
mealie_nutrition = nutritionParser(per_serving)
payload = {'nutrition': mealie_nutrition}
print(f"{payload}")
#updated_recipe = await m_client.recipes.update(recipe_id, payload)
#print(f"{updated_recipe}")
if __name__ == "__main__":
asyncio.run(main())