mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-23 01:02:56 -05:00
improved scraper with debug
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from scrape_schema_recipe import scrape_url
|
||||
from slugify import slugify
|
||||
from utils.logger import logger
|
||||
@@ -5,9 +8,24 @@ from utils.logger import logger
|
||||
from services.image_services import scrape_image
|
||||
from services.recipe_services import Recipe
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
TEMP_FILE = CWD.parent.joinpath("data", "debug", "last_recipe.json")
|
||||
|
||||
|
||||
def normalize_data(recipe_data: dict) -> dict:
|
||||
if type(recipe_data["recipeYield"]) == list:
|
||||
recipe_data["recipeYield"] = recipe_data["recipeYield"][0]
|
||||
|
||||
return recipe_data
|
||||
|
||||
|
||||
def create_from_url(url: str) -> dict:
|
||||
recipe_data = process_recipe_url(url)
|
||||
|
||||
with open(TEMP_FILE, "w") as f:
|
||||
f.write(json.dumps(recipe_data, indent=4, default=str))
|
||||
|
||||
recipe_data = normalize_data(recipe_data)
|
||||
recipe = Recipe(**recipe_data)
|
||||
|
||||
return recipe.save_to_db()
|
||||
|
||||
Reference in New Issue
Block a user