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()]
|
||||
|
||||
|
||||
def reparse_ingredients(session):
|
||||
def get_missing_ingredients(session):
|
||||
cte = (
|
||||
except_(select(db.RecipeIngredient.id), select(db.RecipeIngredientParts.id))
|
||||
).alias("missing")
|
||||
missing = (
|
||||
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:
|
||||
parts = parse_ingredient(ingredient.text)
|
||||
if not 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,
|
||||
)
|
||||
)
|
||||
parts = ingredient_to_parts(ingredient)
|
||||
session.add(parts)
|
||||
|
||||
|
||||
def load_page(recipe_url: str) -> bs4.BeautifulSoup:
|
||||
|
|
|
|||
Loading…
Reference in New Issue