Skip to content

Commit

Permalink
feat: add regex to url before scraping (mealie-recipes#4174)
Browse files Browse the repository at this point in the history
Co-authored-by: Kuchenpirat <[email protected]>
  • Loading branch information
2 people authored and Choromanski committed Oct 1, 2024
1 parent 0a0e798 commit 6fce4a6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mealie/services/scraper/scraper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from re import search as regex_search
from uuid import uuid4

from fastapi import HTTPException, status
Expand Down Expand Up @@ -31,7 +32,13 @@ async def create_from_url(url: str, translator: Translator) -> tuple[Recipe, Scr
Recipe: Recipe Object
"""
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:
raise HTTPException(status.HTTP_400_BAD_REQUEST, {"details": ParserErrors.BAD_RECIPE_DATA.value})
Expand Down

0 comments on commit 6fce4a6

Please sign in to comment.