Skip to content
Closed
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ No matter which deployment option you chose you must setup some environment vari
| `BRING_USERNAME` | The email address of your bring account | Yes | - | `[email protected]` |
| `BRING_PASSWORD` | The password of your bring account | Yes | - | `my super secret password` |
| `BRING_LIST_NAME` | The exact name of the list you want to add the ingredients to, supports special characters | Yes | - | `My shopping list with spaces` |
| `IGNORED_INGREDIENTS` | Ingredients that are never added to the shopping list (things you always have at home), separated by a `,`, case insensitive, **WARNING**: This *only* works for recipes with *enabled* ingredient amounts in the recipe settings! ![recipe settings](./assets/images/recipe_settings.png) | No | - (all ingredients will be added) | `Salt,Pepper,Frying oil` |
| `IGNORED_INGREDIENTS` | Ingredients that are never added to the shopping list (things you always have at home), separated by a `,`, case insensitive, **WARNING**: This *only* works for recipes with *enabled* ingredient amounts in the recipe settings!<br> ![recipe settings](./assets/images/recipe_settings.png). <br>Additionally, any ingredients marked as "On hand" in your Mealie recipes will be automatically ignored and not added to your Bring shopping list. | No | - (all ingredients will be added, except these matching 'On hand') | `Salt,Pepper,Frying oil` |
| `LOG_LEVEL` | The loglevel the application logs at | No | `INFO` | `DEBUG` |
| `HTTP_HOST` | The address the application tries to attach to, leave this empty to listen on all interfaces, leave this empty if you are using Docker | No | `0.0.0.0` | `192.168.1.5` |
| `HTTP_PORT` | The port the application listens on, change this if needed if you run the application locally, leave this empty if you are using Docker | No | `8742` | `1234` |
Expand Down Expand Up @@ -137,3 +137,4 @@ or
$ curl -s -o /dev/null -w "%{http_code}" https://mealie-bring-api.yourlocaldomain.com/status
200
```
````
18 changes: 11 additions & 7 deletions source/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import dataclasses
import uuid


@dataclasses.dataclass
class Ingredient:
name: str
specification: str = None

uuid: str = None
@staticmethod
def from_raw_data(raw_data: dict) -> Ingredient:
return Ingredient(name=Ingredient._get_name(raw_data), specification=Ingredient._get_specification(raw_data))
return Ingredient(name=Ingredient._get_name(raw_data), specification=Ingredient._get_specification(raw_data),uuid=Ingredient._get_uuid(raw_data))

@staticmethod
def _get_name(raw_data: dict) -> str:
return raw_data["food"]["name"]

return raw_data["food"]["name"].capitalize()
@staticmethod
def _get_uuid(raw_data: dict) -> str:
return raw_data.get("reference_id",str(uuid.uuid4()))
@staticmethod
def _get_specification(raw_data: dict) -> str:
specification = f"{Ingredient._get_quantity(raw_data)}{Ingredient._get_unit(raw_data)}"
Expand All @@ -36,7 +37,10 @@ def _get_quantity(raw_data: dict) -> str:
return ""
quantity = int(quantity_raw) if quantity_raw.is_integer() else quantity_raw
return str(quantity)

@staticmethod
def in_household(raw_data: dict) -> str:
ret_val = len(raw_data["food"].get("households_with_ingredient_food",[])) > 0
return ret_val
@staticmethod
def _get_unit(raw_data: dict) -> str:
unit_raw = raw_data["unit"]
Expand Down Expand Up @@ -68,7 +72,7 @@ def is_ignored(name_of_ingredient: str, ignored_ingredients: list[Ingredient]) -
return name_of_ingredient.lower() in [ingredient.name for ingredient in ignored_ingredients]

def to_dict(self) -> dict:
return {"itemId": self.name, "spec": self.specification, "uuid": str(uuid.uuid4())}
return {"itemId": self.name, "spec": self.specification, "uuid": str(self.uuid)}


@dataclasses.dataclass
Expand Down
3 changes: 2 additions & 1 deletion source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def webhook_handler() -> str:
ingredients_to_add.append(IngredientWithAmountsDisabled.from_raw_data(ingredient_raw_data))
else:
name_of_ingredient = ingredient_raw_data["food"]["name"]
if Ingredient.is_ignored(name_of_ingredient, ignored_ingredients):
# Ignore if the ingredient is in the household or on ignored list
if Ingredient.is_ignored(name_of_ingredient, ignored_ingredients) or Ingredient.in_household(ingredient_raw_data):
logger.log.debug(f"Ignoring ingredient {name_of_ingredient}")
continue
ingredients_to_add.append(Ingredient.from_raw_data(ingredient_raw_data))
Expand Down