diff options
author | François Revol <revol@free.fr> | 2016-07-09 20:41:57 +0200 |
---|---|---|
committer | François Revol <revol@free.fr> | 2016-07-12 15:47:04 +0200 |
commit | 1dba6dcbac6891390653170f44cd7ba9de636cd9 (patch) | |
tree | a0c337969d9f4f027f57b51ff6edd5333b5fc3a6 /searx/engines/scanr_structures.py | |
parent | 678b87f9d5969668a07c36f9b80be5a5b2d08587 (diff) | |
download | searxng-1dba6dcbac6891390653170f44cd7ba9de636cd9.tar.gz searxng-1dba6dcbac6891390653170f44cd7ba9de636cd9.zip |
Add ScanR structures search engine
In theory ScanR should also search for projects but the API is different,
so we'd need another engine.
Diffstat (limited to 'searx/engines/scanr_structures.py')
-rw-r--r-- | searx/engines/scanr_structures.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/searx/engines/scanr_structures.py b/searx/engines/scanr_structures.py new file mode 100644 index 000000000..ad78155ac --- /dev/null +++ b/searx/engines/scanr_structures.py @@ -0,0 +1,78 @@ +""" + ScanR Structures (Science) + + @website https://scanr.enseignementsup-recherche.gouv.fr + @provide-api yes (https://scanr.enseignementsup-recherche.gouv.fr/api/swagger-ui.html) + + @using-api yes + @results JSON + @stable yes + @parse url, title, content, img_src +""" + +from urllib import urlencode +from json import loads, dumps +from dateutil import parser +from searx.utils import html_to_text + +# engine dependent config +categories = ['science'] +paging = True +page_size = 20 + +# search-url +url = 'https://scanr.enseignementsup-recherche.gouv.fr/' +search_url = url + 'api/structures/search' + + +# do search-request +def request(query, params): + + params['url'] = search_url + params['method'] = 'POST' + params['headers']['Content-type'] = "application/json" + params['data'] = dumps({"query": query, + "searchField": "ALL", + "sortDirection": "ASC", + "sortOrder": "RELEVANCY", + "page": params['pageno'], + "pageSize": page_size}) + + return params + + +# get response from search-request +def response(resp): + results = [] + + search_res = loads(resp.text) + + # return empty array if there are no results + if search_res.get('total') < 1: + return [] + + # parse results + for result in search_res['results']: + if 'id' not in result: + continue + + # is it thumbnail or img_src?? + thumbnail = None + if 'logo' in result: + thumbnail = result['logo'] + if thumbnail[0] == '/': + thumbnail = url + thumbnail + + content = None + if 'highlights' in result: + content = result['highlights'][0]['value'] + + # append result + results.append({'url': url + 'structure/' + result['id'], + 'title': result['label'], + # 'thumbnail': thumbnail, + 'img_src': thumbnail, + 'content': html_to_text(content)}) + + # return results + return results |