From 7528e38c8a412d9f56eba05b34d2f24f3471f21d Mon Sep 17 00:00:00 2001 From: spongebob33 Date: Fri, 26 Mar 2021 12:22:49 +0100 Subject: [PATCH] add core.ac.uk engine --- searx/engines/core.py | 63 +++++++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 9 +++++++ 2 files changed, 72 insertions(+) create mode 100644 searx/engines/core.py diff --git a/searx/engines/core.py b/searx/engines/core.py new file mode 100644 index 000000000..99b4b524b --- /dev/null +++ b/searx/engines/core.py @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +""" + +Core Engine (science) + +""" + +from json import loads +from datetime import datetime +from urllib.parse import urlencode + +about = { + "website": 'https://core.ac.uk', + "wikidata_id": 'Q22661180', + "official_api_documentation": 'https://core.ac.uk/documentation/api/', + "use_official_api": True, + "require_api_key": True, + "results": 'JSON', +} + +categories = ['science'] + +paging = True +nb_per_page = 20 + + +# apikey = '' +apikey = 'MVBozuTX8QF9I1D0GviL5bCn2Ueat6NS' + + +base_url = 'https://core.ac.uk:443/api-v2/search/' +search_string = '{query}?page={page}&pageSize={nb_per_page}&apiKey={apikey}' + + +def request(query, params): + + search_path = search_string.format( + query=urlencode({'q': query}), + nb_per_page=nb_per_page, + page=params['pageno'], + apikey=apikey) + + params['url'] = base_url + search_path + return params + + +def response(resp): + results = [] + + json_data = loads(resp.text) + for result in json_data['data']: + time = result['_source']['publishedDate'] + if time is None: + date = datetime.now() + else: + date = datetime.fromtimestamp(time / 1000) + results.append({ + 'url': result['_source']['urls'][0], + 'title': result['_source']['title'], + 'content': result['_source']['description'], + 'publishedDate': date}) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 5e0b4cd7d..4217e5bfa 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -272,6 +272,15 @@ engines: categories : images shortcut : cce + - name : core.ac.uk + engine : core + categories : science + shortcut : cor + # get your API key from: https://core.ac.uk/api-keys/register/ + # api_key : "xxxxxxxx" + # set api_key and comment out disabled .. + disabled: True + - name : crossref engine : json_engine paging : True