.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
chefkoch.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Chefkoch is a German database of recipes.
3"""
4
5from datetime import datetime
6from urllib.parse import urlencode
7
8about = {
9 'website': "https://www.chefkoch.de",
10 'official_api_documentation': None,
11 'use_official_api': False,
12 'require_api_key': False,
13 'results': 'JSON',
14 'language': 'de',
15}
16
17paging = True
18categories = []
19
20number_of_results = 20
21skip_premium = True
22
23
24base_url = "https://api.chefkoch.de"
25thumbnail_format = "crop-240x300"
26
27
28def request(query, params):
29 args = {'query': query, 'limit': number_of_results, 'offset': (params['pageno'] - 1) * number_of_results}
30 params['url'] = f"{base_url}/v2/search-gateway/recipes?{urlencode(args)}"
31 return params
32
33
34def response(resp):
35 results = []
36
37 json = resp.json()
38
39 for result in json['results']:
40 recipe = result['recipe']
41
42 if skip_premium and (recipe['isPremium'] or recipe['isPlus']):
43 continue
44
45 publishedDate = None
46 if recipe['submissionDate']:
47 publishedDate = datetime.strptime(result['recipe']['submissionDate'][:19], "%Y-%m-%dT%H:%M:%S")
48
49 content = [
50 f"Schwierigkeitsstufe (1-3): {recipe['difficulty']}",
51 f"Zubereitungszeit: {recipe['preparationTime']}min",
52 f"Anzahl der Zutaten: {recipe['ingredientCount']}",
53 ]
54
55 if recipe['subtitle']:
56 content.insert(0, recipe['subtitle'])
57
58 results.append(
59 {
60 'url': recipe['siteUrl'],
61 'title': recipe['title'],
62 'content': " | ".join(content),
63 'thumbnail': recipe['previewImageUrlTemplate'].replace("<format>", thumbnail_format),
64 'publishedDate': publishedDate,
65 }
66 )
67
68 return results
request(query, params)
Definition chefkoch.py:28