Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add regex to url before scraping
Browse files Browse the repository at this point in the history
jlssmt committed Sep 24, 2024
1 parent 8273761 commit 4e134e5
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
@@ -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})

0 comments on commit 4e134e5

Please sign in to comment.