diff --git a/mealie/routes/recipe/category_routes.py b/mealie/routes/recipe/category_routes.py index 5adf7f4a5..cbded5b9e 100644 --- a/mealie/routes/recipe/category_routes.py +++ b/mealie/routes/recipe/category_routes.py @@ -36,4 +36,4 @@ async def delete_recipe_category( db.categories.delete(session, category) - return SnackResponse(f"Category Deleted: {category}") + return SnackResponse.error(f"Category Deleted: {category}") diff --git a/mealie/services/scrape_services.py b/mealie/services/scrape_services.py index f31604cfe..caa955972 100644 --- a/mealie/services/scrape_services.py +++ b/mealie/services/scrape_services.py @@ -40,7 +40,11 @@ def normalize_instructions(instructions) -> List[dict]: # One long string split by (possibly multiple) new lines if type(instructions) == str: - return [{"text": normalize_instruction(line)} for line in instructions.splitlines() if line] + return [ + {"text": normalize_instruction(line)} + for line in instructions.splitlines() + if line + ] # Plain strings in a list elif type(instructions) == list and type(instructions[0]) == str: @@ -64,7 +68,9 @@ def normalize_instructions(instructions) -> List[dict]: ] return [ - {"text": normalize_instruction(step["text"])} for step in instructions if step["@type"] == "HowToStep" + {"text": normalize_instruction(step["text"])} + for step in instructions + if step["@type"] == "HowToStep" ] except Exception as e: # Not "@type", try "type" @@ -111,8 +117,12 @@ def normalize_data(recipe_data: dict) -> dict: recipe_data["prepTime"] = normalize_time(recipe_data.get("prepTime")) recipe_data["performTime"] = normalize_time(recipe_data.get("performTime")) recipe_data["recipeYield"] = normalize_yield(recipe_data.get("recipeYield")) - recipe_data["recipeIngredient"] = normalize_ingredient(recipe_data.get("recipeIngredient")) - recipe_data["recipeInstructions"] = normalize_instructions(recipe_data["recipeInstructions"]) + recipe_data["recipeIngredient"] = normalize_ingredient( + recipe_data.get("recipeIngredient") + ) + recipe_data["recipeInstructions"] = normalize_instructions( + recipe_data["recipeInstructions"] + ) recipe_data["image"] = normalize_image_url(recipe_data["image"]) return recipe_data @@ -136,11 +146,15 @@ def process_recipe_data(new_recipe: dict, url=None) -> dict: def extract_recipe_from_html(html: str, url: str) -> dict: try: - scraped_recipes: List[dict] = scrape_schema_recipe.loads(html, python_objects=True) + scraped_recipes: List[dict] = scrape_schema_recipe.loads( + html, python_objects=True + ) dump_last_json(scraped_recipes) if not scraped_recipes: - scraped_recipes: List[dict] = scrape_schema_recipe.scrape_url(url, python_objects=True) + scraped_recipes: List[dict] = scrape_schema_recipe.scrape_url( + url, python_objects=True + ) except Exception as e: # trying without python_objects scraped_recipes: List[dict] = scrape_schema_recipe.loads(html) @@ -170,7 +184,7 @@ def download_image_for_recipe(recipe: dict) -> dict: img_path = scrape_image(recipe.get("image"), recipe.get("slug")) recipe["image"] = img_path.name except: - recipe["image"] = None + recipe["image"] = "no image" return recipe