Skip to content

Commit

Permalink
fix: Make recipe scraper cleaner more fault tolerant (mealie-recipes#…
Browse files Browse the repository at this point in the history
…3967)

Co-authored-by: Kuchenpirat <[email protected]>
  • Loading branch information
michael-genson and Kuchenpirat authored Aug 1, 2024
1 parent 05c034f commit 3677d04
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mealie/services/scraper/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def clean_image(image: str | list | dict | None = None, default: str = "no image
case [str(_), *_]:
return [x for x in image if x] # Only return non-null strings in list
case [{"url": str(_)}, *_]:
return [x["url"] for x in image]
return [x["url"] for x in image if "url" in x]
case {"url": str(image)}:
return [image]
case [{"@id": str(_)}, *_]:
return [x["@id"] for x in image]
return [x["@id"] for x in image if "@id" in x]
case _:
logger.exception(f"Unexpected type for image: {type(image)}, {image}")
return [default]
Expand Down Expand Up @@ -149,7 +149,7 @@ def clean_instructions(steps_object: list | dict | str, default: list | None = N
return [
{"text": _sanitize_instruction_text(instruction["text"])}
for instruction in steps_object
if instruction["text"].strip()
if "text" in instruction and instruction["text"].strip()
]
case {0: {"text": str()}} | {"0": {"text": str()}} | {1: {"text": str()}} | {"1": {"text": str()}}:
# Some recipes have a dict with a string key representing the index, unsure if these can
Expand Down

0 comments on commit 3677d04

Please sign in to comment.