Skip to content

Commit

Permalink
Add more logmessages
Browse files Browse the repository at this point in the history
  • Loading branch information
felixschndr committed May 29, 2024
1 parent 73f8c6c commit 32e4b2d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions source/ingredient.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from errors import IgnoredIngredient
from logger_mixin import LoggerMixin


class Ingredient:
def __init__(
self, ingredient_input: dict, ignored_ingredients: list[str]
):
class Ingredient (LoggerMixin):
def __init__(self, ingredient_input: dict, ignored_ingredients: list[str]):
super().__init__()

self.ingredient_input = ingredient_input
self.ignored_ingredients = ignored_ingredients

Expand All @@ -30,22 +31,31 @@ def parse_input(self) -> None:
self._parse_input_with_ingredient_amounts()

def _parse_input_with_no_ingredient_amounts(self) -> None:
self.log.debug("Parsing input with no ingredient amount")
self.food = self.ingredient_input["display"]

def _parse_input_with_ingredient_amounts(self) -> None:
self.log.debug("Parsing input with ingredient amount")
self.log.debug(f"Complete ingredient: {self.ingredient_input}")

food_name = self.ingredient_input["food"]["name"]
if food_name.lower() in self.ignored_ingredients:
raise IgnoredIngredient(f"Found ignored ingredient {food_name}")
self.food = food_name


quantity = self.ingredient_input.get("quantity", None)
if quantity:
self.specification += str(quantity)

unit = self.ingredient_input.get("unit", None)
self.log.debug(f"Unit: {unit}")
if unit:
self.specification += unit.get("abbreviation", unit["name"])
unit_formatted = unit.get("abbreviation", unit["name"])
self.log.debug(f"In if: {unit_formatted}")
self.specification += unit_formatted

self.log.debug(f"Specification afterwards: {self.specification}")

note = self.ingredient_input.get("note", None)
if note:
Expand Down

0 comments on commit 32e4b2d

Please sign in to comment.