.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
scanr_structures.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 ScanR Structures (Science)
4"""
5
6from json import loads, dumps
7from searx.utils import html_to_text
8
9# about
10about = {
11 "website": 'https://scanr.enseignementsup-recherche.gouv.fr',
12 "wikidata_id": 'Q44105684',
13 "official_api_documentation": 'https://scanr.enseignementsup-recherche.gouv.fr/opendata',
14 "use_official_api": True,
15 "require_api_key": False,
16 "results": 'JSON',
17}
18
19# engine dependent config
20categories = ['science']
21paging = True
22page_size = 20
23
24# search-url
25url = 'https://scanr.enseignementsup-recherche.gouv.fr/'
26search_url = url + 'api/structures/search'
27
28
29# do search-request
30def request(query, params):
31
32 params['url'] = search_url
33 params['method'] = 'POST'
34 params['headers']['Content-type'] = "application/json"
35 params['data'] = dumps(
36 {
37 "query": query,
38 "searchField": "ALL",
39 "sortDirection": "ASC",
40 "sortOrder": "RELEVANCY",
41 "page": params['pageno'],
42 "pageSize": page_size,
43 }
44 )
45
46 return params
47
48
49# get response from search-request
50def response(resp):
51 results = []
52
53 search_res = loads(resp.text)
54
55 # return empty array if there are no results
56 if search_res.get('total', 0) < 1:
57 return []
58
59 # parse results
60 for result in search_res['results']:
61 if 'id' not in result:
62 continue
63
64 # is it thumbnail or img_src??
65 thumbnail = None
66 if 'logo' in result:
67 thumbnail = result['logo']
68 if thumbnail[0] == '/':
69 thumbnail = url + thumbnail
70
71 content = None
72 if 'highlights' in result:
73 content = result['highlights'][0]['value']
74
75 # append result
76 results.append(
77 {
78 'url': url + 'structure/' + result['id'],
79 'title': result['label'],
80 # 'thumbnail': thumbnail,
81 'img_src': thumbnail,
82 'content': html_to_text(content),
83 }
84 )
85
86 # return results
87 return results