mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 13:35:23 +02:00
feat: add regex to url before scraping (#4174)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
f8cd8b00a5
commit
38502e82d4
1 changed files with 8 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from re import search as regex_search
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
|
@ -31,7 +32,13 @@ async def create_from_url(url: str, translator: Translator) -> tuple[Recipe, Scr
|
||||||
Recipe: Recipe Object
|
Recipe: Recipe Object
|
||||||
"""
|
"""
|
||||||
scraper = RecipeScraper(translator)
|
scraper = RecipeScraper(translator)
|
||||||
new_recipe, extras = await scraper.scrape(url)
|
|
||||||
|
extracted_url = regex_search(r"(https?://|www\.)[^\s]+", url)
|
||||||
|
|
||||||
|
if not extracted_url:
|
||||||
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, {"details": ParserErrors.BAD_RECIPE_DATA.value})
|
||||||
|
|
||||||
|
new_recipe, extras = await scraper.scrape(extracted_url.group(0))
|
||||||
|
|
||||||
if not new_recipe:
|
if not new_recipe:
|
||||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, {"details": ParserErrors.BAD_RECIPE_DATA.value})
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, {"details": ParserErrors.BAD_RECIPE_DATA.value})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue