summaryrefslogtreecommitdiff
path: root/searx/engines/chefkoch.py
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2023-09-18 11:02:01 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2023-09-21 17:23:59 +0200
commit51236ae47ae24f489f85d63db90302c2d75b8129 (patch)
tree71195cee0c9b41bed13a9fca17158fdeb0cfd7e4 /searx/engines/chefkoch.py
parent8bcca0e620a4879ed37d530419f2da1a709c706e (diff)
[feat] engine: implementation of chefkoch.de
Diffstat (limited to 'searx/engines/chefkoch.py')
-rw-r--r--searx/engines/chefkoch.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/searx/engines/chefkoch.py b/searx/engines/chefkoch.py
new file mode 100644
index 000000000..9dc6ae0dd
--- /dev/null
+++ b/searx/engines/chefkoch.py
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""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 = []
+
+number_of_results = 20
+skip_premium = True
+
+
+base_url = "https://api.chefkoch.de"
+thumbnail_format = "crop-240x300"
+
+
+def request(query, params):
+ args = {'query': query, 'limit': number_of_results, 'offset': (params['pageno'] - 1) * number_of_results}
+ 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.strptime(result['recipe']['submissionDate'][:19], "%Y-%m-%dT%H:%M:%S")
+
+ content = (
+ "difficulity: "
+ + str(recipe['difficulty'])
+ + " / preparation time: "
+ + str(recipe['preparationTime'])
+ + "min / ingredient count: "
+ + str(recipe['ingredientCount'])
+ )
+
+ if recipe['subtitle']:
+ content = f"{recipe['subtitle']} / {content}"
+
+ results.append(
+ {
+ 'url': recipe['siteUrl'],
+ 'title': recipe['title'],
+ 'content': content,
+ 'thumbnail': recipe['previewImageUrlTemplate'].replace("<format>", thumbnail_format),
+ 'publishedDate': publishedDate,
+ }
+ )
+
+ return results