Files
searxng/searx/engines/chefkoch.py
Onev 9e25585aec [refactor] engines: use datetime.fromisoformat instead of datetime.strptime where possible (#6394)
Refactor engines that parse ISO 8601 dates with strptime to use
fromisoformat instead. In most cases this is a direct replacement of
strptime(text, "format") with fromisoformat(text).

For engines where the source has a trailing "Z" that strptime consumed
as a literal (e.g. "%Y-%m-%dT%H:%M:%S.%fZ" in huggingface.py), add
rstrip("Z") to keep the output naive and preserve the existing behavior.

In sogou.py the date is extracted with a regular expression, which can
yield strings like "2026-7-11". strptime accepts this via its format
string, but fromisoformat does not. To preserve the existing behavior
and satisfy the format fromisoformat expects, add zero-padding for the
month and day.

Closes: #6098
---------
Signed-off-by: OneVth <onebrotravel@gmail.com>
2026-07-13 17:46:56 +02:00

68 lines
1.7 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Chefkoch is a German database of recipes."""
from datetime import datetime
from urllib.parse import urlencode
about = {
'website': "https://www.chefkoch.de",
'official_api_documentation': None,
'use_official_api': False,
'require_api_key': False,
'results': 'JSON',
}
language = "de"
paging = True
categories = []
page_size = 20
skip_premium = True
base_url = "https://api.chefkoch.de"
thumbnail_format = "crop-240x300"
def request(query, params):
args = {'query': query, 'limit': page_size, 'offset': (params['pageno'] - 1) * page_size}
params['url'] = f"{base_url}/v2/search-gateway/recipes?{urlencode(args)}"
return params
def response(resp):
results = []
json = resp.json()
for result in json['results']:
recipe = result['recipe']
if skip_premium and (recipe['isPremium'] or recipe['isPlus']):
continue
publishedDate = None
if recipe['submissionDate']:
publishedDate = datetime.fromisoformat(result['recipe']['submissionDate'][:19])
content = [
f"Schwierigkeitsstufe (1-3): {recipe['difficulty']}",
f"Zubereitungszeit: {recipe['preparationTime']}min",
f"Anzahl der Zutaten: {recipe['ingredientCount']}",
]
if recipe['subtitle']:
content.insert(0, recipe['subtitle'])
results.append(
{
'url': recipe['siteUrl'],
'title': recipe['title'],
'content': " | ".join(content),
'thumbnail': recipe['previewImageUrlTemplate'].replace("<format>", thumbnail_format),
'publishedDate': publishedDate,
}
)
return results