Refactor/recipe routes (#370)

* format with black

* black format

* flake8

* remove bar exceptions

* remove test for depreciated route

* recipe settings editr

* add sqlite

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-04-29 21:46:27 -08:00
committed by GitHub
parent 5dafe8fbb5
commit 1dc051f562
38 changed files with 179 additions and 224 deletions

View File

@@ -37,7 +37,7 @@ class ExportDatabase:
try:
self.templates = [app_dirs.TEMPLATE_DIR.joinpath(x) for x in templates]
except:
except Exception:
self.templates = False
logger.info("No Jinja2 Templates Registered for Export")

View File

@@ -84,20 +84,20 @@ class ImportDatabase:
try:
del recipe_dict["_id"]
del recipe_dict["date_added"]
except:
except Exception:
pass
# Migration from list to Object Type Data
try:
if "" in recipe_dict["tags"]:
recipe_dict["tags"] = [tag for tag in recipe_dict["tags"] if tag != ""]
except:
except Exception:
pass
try:
if "" in recipe_dict["categories"]:
recipe_dict["categories"] = [cat for cat in recipe_dict["categories"] if cat != ""]
except:
except Exception:
pass
if type(recipe_dict["extras"]) == list:

View File

@@ -54,7 +54,7 @@ def rename_image(original_slug, new_slug) -> Path:
def write_image(recipe_slug: str, file_data: bytes, extension: str) -> Path:
try:
delete_image(recipe_slug)
except:
except Exception:
pass
image_dir = Path(app_dirs.IMG_DIR.joinpath(f"{recipe_slug}"))
@@ -100,7 +100,7 @@ def scrape_image(image_url: str, slug: str) -> Path:
try:
r = requests.get(image_url, stream=True)
except:
except Exception:
logger.exception("Fatal Image Request Exception")
return None

View File

@@ -35,14 +35,15 @@ def minify_image(image_file: Path) -> ImageSizes:
min_dest (Path): FULL Destination File Path
tiny_dest (Path): FULL Destination File Path
"""
def cleanup(dir: Path) -> None:
for file in dir.glob("*.*"):
if file.suffix != ".webp":
file.unlink()
org_dest = image_file.parent.joinpath(f"original.webp")
min_dest = image_file.parent.joinpath(f"min-original.webp")
tiny_dest = image_file.parent.joinpath(f"tiny-original.webp")
org_dest = image_file.parent.joinpath("original.webp")
min_dest = image_file.parent.joinpath("min-original.webp")
tiny_dest = image_file.parent.joinpath("tiny-original.webp")
if min_dest.exists() and tiny_dest.exists() and org_dest.exists():
return

View File

@@ -24,7 +24,7 @@ def process_meals(session: Session, meal_plan_base: MealPlanIn) -> MealPlanProce
description=recipe.description,
)
except:
except Exception:
meal_data = MealOut(
date=meal_plan_base.startDate + timedelta(days=x),

View File

@@ -8,7 +8,7 @@ from mealie.core import root_logger
from mealie.db.database import db
from mealie.schema.migration import MigrationImport
from mealie.schema.recipe import Recipe
from mealie.services.image import image, minify
from mealie.services.image import image
from mealie.services.scraper.cleaner import Cleaner
from mealie.utils.unzip import unpack_zip
from pydantic import BaseModel

View File

@@ -115,7 +115,7 @@ class Cleaner:
for step in instructions
if step["type"].find("HowToStep") > -1
]
except:
except Exception:
pass
else:

View File

@@ -21,7 +21,7 @@ def basic_recipe_from_opengraph(html: str, url: str) -> dict:
data = extruct.extract(html, base_url=base_url)
try:
properties = data["opengraph"][0]["properties"]
except:
except Exception:
return
return {

View File

@@ -67,7 +67,7 @@ def download_image_for_recipe(recipe: dict) -> dict:
try:
img_path = scrape_image(recipe.get("image"), recipe.get("slug"))
recipe["image"] = img_path.name
except:
except Exception:
recipe["image"] = "no image"
return recipe