refactor
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a04bb06ed8
commit
9d0413ada5
|
|
@ -64,30 +64,20 @@ def parse_ingredient(
|
||||||
|
|
||||||
return [text.strip() if text else None for text in m.groups()]
|
return [text.strip() if text else None for text in m.groups()]
|
||||||
|
|
||||||
|
def get_missing_ingredients(session):
|
||||||
def reparse_ingredients(session):
|
|
||||||
cte = (
|
cte = (
|
||||||
except_(select(db.RecipeIngredient.id), select(db.RecipeIngredientParts.id))
|
except_(select(db.RecipeIngredient.id), select(db.RecipeIngredientParts.id))
|
||||||
).alias("missing")
|
).alias("missing")
|
||||||
missing = (
|
missing = (
|
||||||
session.query(db.RecipeIngredient).where(db.RecipeIngredient.id.in_(cte)).all()
|
session.query(db.RecipeIngredient).where(db.RecipeIngredient.id.in_(cte)).all()
|
||||||
)
|
)
|
||||||
|
return missing
|
||||||
|
|
||||||
|
def reparse_ingredients(session):
|
||||||
|
missing = get_missing_ingredients(session)
|
||||||
for ingredient in missing:
|
for ingredient in missing:
|
||||||
parts = parse_ingredient(ingredient.text)
|
parts = ingredient_to_parts(ingredient)
|
||||||
if not parts:
|
session.add(parts)
|
||||||
continue
|
|
||||||
quantity, unit, instruction, name, supplement = parts
|
|
||||||
session.add(
|
|
||||||
db.RecipeIngredientParts(
|
|
||||||
id=ingredient.id,
|
|
||||||
quantity=quantity,
|
|
||||||
unit=unit,
|
|
||||||
instruction=instruction,
|
|
||||||
ingredient=name,
|
|
||||||
supplement=supplement,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def load_page(recipe_url: str) -> bs4.BeautifulSoup:
|
def load_page(recipe_url: str) -> bs4.BeautifulSoup:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue