Skip to content

Commit

Permalink
chore: bump user agent (#3457)
Browse files Browse the repository at this point in the history
  • Loading branch information
hay-kot committed Apr 29, 2024
1 parent 786aa22 commit c236600
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
7 changes: 6 additions & 1 deletion mealie/services/recipe/recipe_data_service.py
Expand Up @@ -10,7 +10,12 @@
from mealie.schema.recipe.recipe import Recipe
from mealie.services._base_service import BaseService

_FIREFOX_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"
try:
from recipe_scrapers._abstract import HEADERS

_FIREFOX_UA = HEADERS["User-Agent"]
except (ImportError, KeyError):
_FIREFOX_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0"


async def gather_with_concurrency(n, *coros, ignore_exceptions=False):
Expand Down
24 changes: 20 additions & 4 deletions mealie/services/scraper/scraper_strategies.py
Expand Up @@ -18,7 +18,14 @@

from . import cleaner

_FIREFOX_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"
try:
from recipe_scrapers._abstract import HEADERS

_FIREFOX_UA = HEADERS["User-Agent"]
except (ImportError, KeyError):
_FIREFOX_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0"


SCRAPER_TIMEOUT = 15


Expand Down Expand Up @@ -106,7 +113,11 @@ async def get_html(self, url: str) -> str:

def clean_scraper(self, scraped_data: SchemaScraperFactory.SchemaScraper, url: str) -> tuple[Recipe, ScrapedExtras]:
def try_get_default(
func_call: Callable | None, get_attr: str, default: Any, clean_func=None, **clean_func_kwargs
func_call: Callable | None,
get_attr: str,
default: Any,
clean_func=None,
**clean_func_kwargs,
):
value = default

Expand All @@ -129,7 +140,9 @@ def try_get_default(

def get_instructions() -> list[RecipeStep]:
instruction_as_text = try_get_default(
scraped_data.instructions, "recipeInstructions", ["No Instructions Found"]
scraped_data.instructions,
"recipeInstructions",
["No Instructions Found"],
)

self.logger.debug(f"Scraped Instructions: (Type: {type(instruction_as_text)}) \n {instruction_as_text}")
Expand Down Expand Up @@ -159,7 +172,10 @@ def get_instructions() -> list[RecipeStep]:
nutrition=try_get_default(None, "nutrition", None, cleaner.clean_nutrition),
recipe_yield=try_get_default(scraped_data.yields, "recipeYield", "1", cleaner.clean_string),
recipe_ingredient=try_get_default(
scraped_data.ingredients, "recipeIngredient", [""], cleaner.clean_ingredients
scraped_data.ingredients,
"recipeIngredient",
[""],
cleaner.clean_ingredients,
),
recipe_instructions=get_instructions(),
total_time=try_get_default(None, "totalTime", None, cleaner.clean_time, translator=self.translator),
Expand Down
17 changes: 1 addition & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -34,7 +34,7 @@ python-dotenv = "^1.0.0"
python-ldap = "^3.3.1"
python-multipart = "^0.0.9"
python-slugify = "^8.0.0"
recipe-scrapers = "^14.53.0"
recipe-scrapers = "^14.55.0"
requests = "^2.31.0"
tzdata = "^2023.4"
uvicorn = { extras = ["standard"], version = "^0.29.0" }
Expand Down

0 comments on commit c236600

Please sign in to comment.