Skip to content

Commit

Permalink
re-ordered case to favor better implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-genson committed Dec 11, 2023
1 parent f4e0c6e commit c07e0c3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mealie/services/scraper/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def clean_image(image: str | list | dict | None = None, default: str = "no image
image attempts to parse the image field from a recipe and return a string. Currenty
Supported Structures:
- `https://exmaple.com` - A string
- `{ "url": "https://exmaple.com" }` - A dictionary with a `url` key
- `["https://exmaple.com"]` - A list of strings
- `[{ "url": "https://exmaple.com" }]` - A list of dictionaries with a `url` key
- `https://example.com` - A string
- `{ "url": "https://example.com" }` - A dictionary with a `url` key
- `["https://example.com"]` - A list of strings
- `[{ "url": "https://example.com" }]` - A list of dictionaries with a `url` key
Raises:
TypeError: If the image field is not a supported type a TypeError is raised.
Expand All @@ -108,12 +108,12 @@ def clean_image(image: str | list | dict | None = None, default: str = "no image
return [image]
case [str(_), *_]:
return [x for x in image if x] # Only return non-null strings in list
case [{"@id": str(_)}, *_]:
return [x["@id"] for x in image]
case [{"url": str(_)}, *_]:
return [x["url"] for x in image]
case {"url": str(image)}:
return [image]
case [{"@id": str(_)}, *_]:
return [x["@id"] for x in image]
case _:
logger.exception(f"Unexpected type for image: {type(image)}, {image}")
return [default]
Expand Down

0 comments on commit c07e0c3

Please sign in to comment.