summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/__init__.py16
-rw-r--r--searx/engines/microsoft_academic.py77
2 files changed, 8 insertions, 85 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index 7e8336e01..ca3b5d4a8 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -13,7 +13,7 @@ usage::
import sys
import copy
-from typing import List
+from typing import Dict, List, Optional
from os.path import realpath, dirname
from babel.localedata import locale_identifiers
@@ -67,10 +67,10 @@ class Engine: # pylint: disable=too-few-public-methods
timeout: float
-# Defaults for the namespace of an engine module, see :py:func:`load_engine``
+# Defaults for the namespace of an engine module, see :py:func:`load_engine`
categories = {'general': []}
-engines = {}
+engines: Dict[str, Engine] = {}
engine_shortcuts = {}
"""Simple map of registered *shortcuts* to name of the engine (or ``None``).
@@ -81,7 +81,7 @@ engine_shortcuts = {}
"""
-def load_engine(engine_data):
+def load_engine(engine_data: dict) -> Optional[Engine]:
"""Load engine from ``engine_data``.
:param dict engine_data: Attributes from YAML ``settings:engines/<engine>``
@@ -157,7 +157,7 @@ def set_loggers(engine, engine_name):
module.logger = logger.getChild(module_engine_name)
-def update_engine_attributes(engine, engine_data):
+def update_engine_attributes(engine: Engine, engine_data):
# set engine attributes from engine_data
for param_name, param_value in engine_data.items():
if param_name == 'categories':
@@ -175,7 +175,7 @@ def update_engine_attributes(engine, engine_data):
setattr(engine, arg_name, copy.deepcopy(arg_value))
-def set_language_attributes(engine):
+def set_language_attributes(engine: Engine):
# assign supported languages from json file
if engine.name in ENGINES_LANGUAGES:
engine.supported_languages = ENGINES_LANGUAGES[engine.name]
@@ -248,7 +248,7 @@ def is_missing_required_attributes(engine):
return missing
-def is_engine_active(engine):
+def is_engine_active(engine: Engine):
# check if engine is inactive
if engine.inactive is True:
return False
@@ -260,7 +260,7 @@ def is_engine_active(engine):
return True
-def register_engine(engine):
+def register_engine(engine: Engine):
if engine.name in engines:
logger.error('Engine config error: ambigious name: {0}'.format(engine.name))
sys.exit(1)
diff --git a/searx/engines/microsoft_academic.py b/searx/engines/microsoft_academic.py
deleted file mode 100644
index a869daf2f..000000000
--- a/searx/engines/microsoft_academic.py
+++ /dev/null
@@ -1,77 +0,0 @@
-# SPDX-License-Identifier: AGPL-3.0-or-later
-"""
- Microsoft Academic (Science)
-"""
-
-from json import dumps, loads
-from searx.utils import html_to_text
-
-# about
-about = {
- "website": 'https://academic.microsoft.com',
- "wikidata_id": 'Q28136779',
- "official_api_documentation": 'http://ma-graph.org/',
- "use_official_api": False,
- "require_api_key": False,
- "results": 'JSON',
-}
-
-categories = ['images']
-paging = True
-search_url = 'https://academic.microsoft.com/api/search'
-_paper_url = 'https://academic.microsoft.com/paper/{id}/reference'
-
-
-def request(query, params):
- params['url'] = search_url
- params['method'] = 'POST'
- params['headers']['content-type'] = 'application/json; charset=utf-8'
- params['data'] = dumps(
- {
- 'query': query,
- 'queryExpression': '',
- 'filters': [],
- 'orderBy': 0,
- 'skip': (params['pageno'] - 1) * 10,
- 'sortAscending': True,
- 'take': 10,
- 'includeCitationContexts': False,
- 'profileId': '',
- }
- )
-
- return params
-
-
-def response(resp):
- results = []
- response_data = loads(resp.text)
- if not response_data:
- return results
-
- for result in response_data.get('pr', {}):
- if 'dn' not in result['paper']:
- continue
-
- title = result['paper']['dn']
- content = _get_content(result['paper'])
- url = _paper_url.format(id=result['paper']['id'])
- results.append(
- {
- 'url': url,
- 'title': html_to_text(title),
- 'content': html_to_text(content),
- }
- )
-
- return results
-
-
-def _get_content(result):
- if 'd' in result:
- content = result['d']
- if len(content) > 300:
- return content[:300] + '...'
- return content
-
- return ''