From 55d523c8db18955fd6765a6e15508c41ff6f2fb3 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 8 Sep 2023 08:40:48 +0200 Subject: [PATCH] [feat] engine: implementation of Yummly Co-authored-by: Markus Heiser --- searx/engines/yummly.py | 79 +++++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 5 +++ 2 files changed, 84 insertions(+) create mode 100644 searx/engines/yummly.py diff --git a/searx/engines/yummly.py b/searx/engines/yummly.py new file mode 100644 index 000000000..25285ef7c --- /dev/null +++ b/searx/engines/yummly.py @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +"""Yummly +""" + +from urllib.parse import urlencode + +from flask_babel import gettext +from searx.utils import markdown_to_text + +about = { + "website": 'https://yummly.com', + "wikidata_id": 'Q8061140', + # not used since it requires an api key + "official_api_documentation": 'https://developer.yummly.com/documentation.html', + "use_official_api": False, + "require_api_key": False, + "results": 'JSON', +} +paging = True +categories = [] + +api_url = "https://mapi.yummly.com" +number_of_results = 10 +show_pro_recipes = False +base_url = "https://www.yummly.com" + + +def request(query, params): + args = { + 'q': query, + 'start': (params['pageno'] - 1) * number_of_results, + 'maxResult': number_of_results, + } + + params['url'] = f"{api_url}/mapi/v23/content/search?{urlencode(args)}&allowedContent=single_recipe" + + return params + + +def response(resp): + results = [] + + json = resp.json() + + for result in json['feed']: + # don't show pro recipes since they can't be accessed without an account + if not show_pro_recipes and result['proRecipe']: + continue + + content = result['seo']['web']['meta-tags']['description'] + description = result['content']['description'] + if description is not None: + content = markdown_to_text(description['text']) + + img_src = None + if result['display']['images']: + img_src = result['display']['images'][0] + elif result['content']['details']['images']: + img_src = result['content']['details']['images'][0]['resizableImageUrl'] + + url = result['display']['source']['sourceRecipeUrl'] + if 'www.yummly.com/private' in url: + url = base_url + '/' + result['tracking-id'] + + results.append( + { + 'url': url, + 'title': result['display']['displayName'], + 'content': content, + 'img_src': img_src, + 'metadata': f"{gettext('Language')}: {result['locale'].split('-')[0]}", + } + ) + + for suggestion in json['relatedPhrases']['keywords']: + results.append({'suggestion': suggestion}) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index a1347ce52..441f3e3f2 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1894,6 +1894,11 @@ engines: shortcut: wttr timeout: 9.0 + - name: yummly + engine: yummly + shortcut: yum + disabled: true + - name: brave engine: brave shortcut: br