.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
pinterest.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Pinterest (images)
3"""
4
5from json import dumps
6
7about = {
8 "website": 'https://www.pinterest.com/',
9 "wikidata_id": 'Q255381',
10 "official_api_documentation": 'https://developers.pinterest.com/docs/api/v5/',
11 "use_official_api": False,
12 "require_api_key": False,
13 "results": 'JSON',
14}
15
16categories = ['images']
17paging = True
18
19base_url = 'https://www.pinterest.com'
20
21
22def request(query, params):
23 args = {
24 'options': {
25 'query': query,
26 'bookmarks': [params['engine_data'].get('bookmark', '')],
27 },
28 'context': {},
29 }
30 params['url'] = f"{base_url}/resource/BaseSearchResource/get/?data={dumps(args)}"
31
32 return params
33
34
35def response(resp):
36 results = []
37
38 json_resp = resp.json()
39
40 results.append(
41 {
42 'engine_data': json_resp['resource_response']['bookmark'],
43 # it's called bookmark by pinterest, but it's rather a nextpage
44 # parameter to get the next results
45 'key': 'bookmark',
46 }
47 )
48
49 for result in json_resp['resource_response']['data']['results']:
50
51 if result['type'] == 'story':
52 continue
53
54 results.append(
55 {
56 'template': 'images.html',
57 'url': result['link'] or f"{base_url}/pin/{result['id']}/",
58 'title': result.get('title') or result.get('grid_title'),
59 'content': (result.get('rich_summary') or {}).get('display_description') or "",
60 'img_src': result['images']['orig']['url'],
61 'thumbnail_src': result['images']['236x']['url'],
62 'source': (result.get('rich_summary') or {}).get('site_name'),
63 }
64 )
65
66 return results
request(query, params)
Definition pinterest.py:22