[foods] Add catch for common domain exclusions
This commit is contained in:
3
vrobbler/apps/foods/constants.py
Normal file
3
vrobbler/apps/foods/constants.py
Normal file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
EXCLUDED_FOOD_DOMAINS = ["bbc.co.uk", "bbc.com", "www.bbc.com"]
|
||||
@ -1,11 +1,17 @@
|
||||
import logging
|
||||
from typing import Dict, List, Optional
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
from django.core.files.base import ContentFile
|
||||
from foods.constants import EXCLUDED_FOOD_DOMAINS
|
||||
from recipe_scrapers import scrape_html
|
||||
from recipe_scrapers._exceptions import (
|
||||
NoSchemaFoundInWildMode,
|
||||
SchemaOrgException,
|
||||
)
|
||||
import requests
|
||||
from typing import Dict, Optional, List
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RecipeScraperService:
|
||||
@ -73,6 +79,10 @@ class RecipeScraperService:
|
||||
@classmethod
|
||||
def is_recipe_url(cls, url: str) -> bool:
|
||||
"""Check if a URL points to a recipe by fetching and checking the HTML."""
|
||||
domain = urlparse(url).netloc
|
||||
if domain in EXCLUDED_FOOD_DOMAINS and "food" not in url:
|
||||
logger.info("[food] domain found in EXCLUDED_FOOD_DOMAINS")
|
||||
return False
|
||||
try:
|
||||
response = requests.get(
|
||||
url,
|
||||
@ -86,7 +96,6 @@ class RecipeScraperService:
|
||||
return False
|
||||
return cls.is_recipe(response.text, url)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def _safe_call(self, scraper, method, default=None):
|
||||
|
||||
Reference in New Issue
Block a user