Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nutrition #47

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
ignore = D203,W503
extend-ignore = E701
exclude = .git,__pycache__,build,dist
max-line-length = 119
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ repos:
- id: pyupgrade
args: [--py310-plus]
- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black
language_version: python3.11

language_version: python3.13
- repo: https://github.com/timothycrosley/isort
# isort config is in setup.cfg
rev: 5.13.2
Expand Down
29 changes: 14 additions & 15 deletions kptncook/mealie.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class UnitFoodBase(NameIsIdModel):
description: str = ""


class RecipeFood(UnitFoodBase):
...
class RecipeFood(UnitFoodBase): ...


class RecipeUnit(UnitFoodBase):
Expand Down Expand Up @@ -109,13 +108,13 @@ class RecipeStep(BaseModel):


class Nutrition(BaseModel):
calories: str | int | None = None
fat_content: str | None = None
protein_content: str | None = None
carbohydrate_content: str | None = None
fiber_content: str | None = None
sodium_content: str | None = None
sugar_content: str | None = None
calories: str | None = None
fatContent: str | None = None
proteinContent: str | None = None
carbohydrateContent: str | None = None
fiberContent: str | None = None
sodiumContent: str | None = None
sugarContent: str | None = None


class RecipeSettings(BaseModel):
Expand Down Expand Up @@ -230,7 +229,7 @@ def enrich_recipe_with_step_images(self, recipe):
instruction.text = self._build_recipestep_text(
recipe.id, instruction.text, uploaded_image_name
)
assets.append(RecipeAsset(name=asset_properties["name"], icon=asset_properties["icon"], file_name=asset_properties["fileName"]))
assets.append(RecipeAsset(name=asset_properties["name"], icon=asset_properties["icon"], file_name=asset_properties["fileName"])) # fmt: skip # noqa: E501
recipe.assets = assets
return recipe

Expand Down Expand Up @@ -422,11 +421,11 @@ def kptncook_to_mealie(
RecipeNote(title="author comment", text=kcin.author_comment.de),
],
"nutrition": Nutrition(
calories=kcin.recipe_nutrition.calories,
proteinContent=kcin.recipe_nutrition.protein,
fatContent=kcin.recipe_nutrition.fat,
carbohydrateContent=kcin.recipe_nutrition.carbohydrate,
), # type: ignore
calories=str(kcin.recipe_nutrition.calories),
proteinContent=str(kcin.recipe_nutrition.protein),
fatContent=str(kcin.recipe_nutrition.fat),
carbohydrateContent=str(kcin.recipe_nutrition.carbohydrate),
),
"prep_time": kcin.preparation_time,
"cook_time": kcin.cooking_time,
"recipe_yield": "1 Portionen",
Expand Down
9 changes: 9 additions & 0 deletions tests/to_mealie_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def test_parse_full_recipe(full_recipe):
assert mealie_recipe.extras is not None
assert "kptncook_id" in mealie_recipe.extras
assert mealie_recipe.extras["source"] == "kptncook"

assert mealie_recipe.nutrition is not None
assert mealie_recipe.nutrition.calories == "900"
assert mealie_recipe.nutrition.fatContent == "41"
assert mealie_recipe.nutrition.proteinContent == "40"
assert mealie_recipe.nutrition.carbohydrateContent == "85"
assert mealie_recipe.nutrition.fiberContent is None
assert mealie_recipe.nutrition.sodiumContent is None
assert mealie_recipe.nutrition.sugarContent is None