mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
bug/normalize recipe steps html
This commit is contained in:
parent
34a10f375f
commit
732a2cbc51
1 changed files with 11 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import html
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
@ -5,7 +6,6 @@ from typing import List, Tuple
|
||||||
import extruct
|
import extruct
|
||||||
import requests
|
import requests
|
||||||
import scrape_schema_recipe
|
import scrape_schema_recipe
|
||||||
import html
|
|
||||||
from app_config import DEBUG_DIR
|
from app_config import DEBUG_DIR
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
from utils.logger import logger
|
from utils.logger import logger
|
||||||
|
@ -33,7 +33,9 @@ def normalize_instructions(instructions) -> List[dict]:
|
||||||
# One long string split by (possibly multiple) new lines
|
# One long string split by (possibly multiple) new lines
|
||||||
if type(instructions) == str:
|
if type(instructions) == str:
|
||||||
return [
|
return [
|
||||||
{"text": normalize_instruction(line)} for line in instructions.splitlines() if line
|
{"text": normalize_instruction(line)}
|
||||||
|
for line in instructions.splitlines()
|
||||||
|
if line
|
||||||
]
|
]
|
||||||
|
|
||||||
# Plain strings in a list
|
# Plain strings in a list
|
||||||
|
@ -60,6 +62,10 @@ def normalize_instruction(line) -> str:
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_ingredient(ingredients: list) -> str:
|
||||||
|
return [html.unescape(ing) for ing in ingredients]
|
||||||
|
|
||||||
|
|
||||||
def normalize_yield(yld) -> str:
|
def normalize_yield(yld) -> str:
|
||||||
if type(yld) == list:
|
if type(yld) == list:
|
||||||
return yld[-1]
|
return yld[-1]
|
||||||
|
@ -79,6 +85,9 @@ def normalize_data(recipe_data: dict) -> dict:
|
||||||
recipe_data["prepTime"] = normalize_time(recipe_data.get("prepTime"))
|
recipe_data["prepTime"] = normalize_time(recipe_data.get("prepTime"))
|
||||||
recipe_data["performTime"] = normalize_time(recipe_data.get("performTime"))
|
recipe_data["performTime"] = normalize_time(recipe_data.get("performTime"))
|
||||||
recipe_data["recipeYield"] = normalize_yield(recipe_data.get("recipeYield"))
|
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"] = normalize_instructions(
|
||||||
recipe_data["recipeInstructions"]
|
recipe_data["recipeInstructions"]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue