.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
yummly.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Yummly
3"""
4
5from urllib.parse import urlencode
6
7from flask_babel import gettext
8from searx.utils import markdown_to_text
9
10about = {
11 "website": 'https://yummly.com',
12 "wikidata_id": 'Q8061140',
13 # not used since it requires an api key
14 "official_api_documentation": 'https://developer.yummly.com/documentation.html',
15 "use_official_api": False,
16 "require_api_key": False,
17 "results": 'JSON',
18}
19paging = True
20categories = []
21
22api_url = "https://mapi.yummly.com"
23number_of_results = 10
24show_pro_recipes = False
25base_url = "https://www.yummly.com"
26
27
28def request(query, params):
29 args = {
30 'q': query,
31 'start': (params['pageno'] - 1) * number_of_results,
32 'maxResult': number_of_results,
33 }
34
35 params['url'] = f"{api_url}/mapi/v23/content/search?{urlencode(args)}&allowedContent=single_recipe"
36
37 return params
38
39
40def response(resp):
41 results = []
42
43 json = resp.json()
44
45 for result in json['feed']:
46 # don't show pro recipes since they can't be accessed without an account
47 if not show_pro_recipes and result['proRecipe']:
48 continue
49
50 content = result['seo']['web']['meta-tags']['description']
51 description = result['content']['description']
52 if description is not None:
53 content = markdown_to_text(description['text'])
54
55 img_src = None
56 if result['display']['images']:
57 img_src = result['display']['images'][0]
58 elif result['content']['details']['images']:
59 img_src = result['content']['details']['images'][0]['resizableImageUrl']
60
61 url = result['display']['source']['sourceRecipeUrl']
62 if 'www.yummly.com/private' in url:
63 url = base_url + '/' + result['tracking-id']
64
65 results.append(
66 {
67 'url': url,
68 'title': result['display']['displayName'],
69 'content': content,
70 'img_src': img_src,
71 'metadata': gettext('Language') + f": {result['locale'].split('-')[0]}",
72 }
73 )
74
75 for suggestion in json['relatedPhrases']['keywords']:
76 results.append({'suggestion': suggestion})
77
78 return results
request(query, params)
Definition yummly.py:28