diff options
author | Bnyro <bnyro@tutanota.com> | 2023-09-25 18:06:18 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-09-30 15:01:45 +0200 |
commit | 5ce1792432e00c723ba6b1a337abd06e472aee4a (patch) | |
tree | 5926c6d600ba98981ad3f4ab14d92ddac4d73fa8 /searx | |
parent | 6096457e4d42ab7d2338b89b49f76e6118c5202e (diff) | |
download | searxng-5ce1792432e00c723ba6b1a337abd06e472aee4a.tar.gz searxng-5ce1792432e00c723ba6b1a337abd06e472aee4a.zip |
[feat] engine: implementation of pinterest
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/pinterest.py | 63 | ||||
-rw-r--r-- | searx/settings.yml | 4 |
2 files changed, 67 insertions, 0 deletions
diff --git a/searx/engines/pinterest.py b/searx/engines/pinterest.py new file mode 100644 index 000000000..4ca316698 --- /dev/null +++ b/searx/engines/pinterest.py @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +"""Pinterest (images) +""" + +from json import dumps + +about = { + "website": 'https://www.pinterest.com/', + "wikidata_id": 'Q255381', + "official_api_documentation": 'https://developers.pinterest.com/docs/api/v5/', + "use_official_api": False, + "require_api_key": False, + "results": 'JSON', +} + +categories = ['images'] +paging = True + +base_url = 'https://www.pinterest.com' + + +def request(query, params): + args = { + 'options': { + 'query': query, + 'bookmarks': [params['engine_data'].get('bookmark', '')], + }, + 'context': {}, + } + params['url'] = f"{base_url}/resource/BaseSearchResource/get/?data={dumps(args)}" + + return params + + +def response(resp): + results = [] + + json_resp = resp.json() + + results.append( + { + 'engine_data': json_resp['resource_response']['bookmark'], + # it's called bookmark by pinterest, but it's rather a nextpage + # parameter to get the next results + 'key': 'bookmark', + } + ) + + for result in json_resp['resource_response']['data']['results']: + results.append( + { + 'template': 'images.html', + 'url': result['link'] or f"{base_url}/pin/{result['id']}/", + 'title': result.get('title') or result.get('grid_title'), + 'content': (result.get('rich_summary') or {}).get('display_description') or "", + 'img_src': result['images']['orig']['url'], + 'thumbnail_src': result['images']['236x']['url'], + 'source': (result.get('rich_summary') or {}).get('site_name'), + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 848dc95df..951378eb4 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1204,6 +1204,10 @@ engines: engine: photon shortcut: ph + - name: pinterest + engine: pinterest + shortcut: pin + - name: piped engine: piped shortcut: ppd |