.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
4from json import dumps
5
6about = {
7 "website": 'https://www.pinterest.com/',
8 "wikidata_id": 'Q255381',
9 "official_api_documentation": 'https://developers.pinterest.com/docs/api/v5/',
10 "use_official_api": False,
11 "require_api_key": False,
12 "results": 'JSON',
13}
14
15categories = ['images']
16paging = True
17
18base_url = 'https://www.pinterest.com'
19
20
21def request(query, params):
22 args = {
23 'options': {
24 'query': query,
25 'bookmarks': [params['engine_data'].get('bookmark', '')],
26 },
27 'context': {},
28 }
29 params['url'] = f"{base_url}/resource/BaseSearchResource/get/?data={dumps(args)}"
30 params['headers'] = {
31 'X-Pinterest-AppState': 'active',
32 'X-Pinterest-Source-Url': '/ideas/',
33 'X-Pinterest-PWS-Handler': 'www/ideas.js',
34 }
35
36 return params
37
38
39def response(resp):
40 results = []
41
42 json_resp = resp.json()
43
44 results.append(
45 {
46 'engine_data': json_resp['resource_response']['bookmark'],
47 # it's called bookmark by pinterest, but it's rather a nextpage
48 # parameter to get the next results
49 'key': 'bookmark',
50 }
51 )
52
53 for result in json_resp['resource_response']['data']['results']:
54
55 if result['type'] == 'story':
56 continue
57
58 results.append(
59 {
60 'template': 'images.html',
61 'url': result['link'] or f"{base_url}/pin/{result['id']}/",
62 'title': result.get('title') or result.get('grid_title'),
63 'content': (result.get('rich_summary') or {}).get('display_description') or "",
64 'img_src': result['images']['orig']['url'],
65 'thumbnail_src': result['images']['236x']['url'],
66 'source': (result.get('rich_summary') or {}).get('site_name'),
67 }
68 )
69
70 return results
request(query, params)
Definition pinterest.py:21