diff options
| author | Alexandre Flament <alex@al-f.net> | 2020-12-17 11:49:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-17 11:49:43 +0100 |
| commit | 9b27935f71ea94ba034d73c09c1f18df05fd33b6 (patch) | |
| tree | c1e7b116220d72f9e541ff4e7e5b108dd8a2f2aa /searx/search/processors/online_dictionary.py | |
| parent | 13a2b1a44d0e216d3750519239fab2c0abb142e4 (diff) | |
| parent | 02fc4147ce745325ff25146a8085a915a5d3cacd (diff) | |
Merge pull request #2225 from dalf/processors
Processors
Diffstat (limited to 'searx/search/processors/online_dictionary.py')
| -rw-r--r-- | searx/search/processors/online_dictionary.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/searx/search/processors/online_dictionary.py b/searx/search/processors/online_dictionary.py new file mode 100644 index 000000000..8e9ef1620 --- /dev/null +++ b/searx/search/processors/online_dictionary.py @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +import re + +from searx.utils import is_valid_lang +from .online import OnlineProcessor + + +parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I) + + +class OnlineDictionaryProcessor(OnlineProcessor): + + engine_type = 'online_dictionnary' + + def get_params(self, search_query, engine_category): + params = super().get_params(search_query, engine_category) + if params is None: + return None + + m = parser_re.match(search_query.query) + if not m: + return None + + from_lang, to_lang, query = m.groups() + + from_lang = is_valid_lang(from_lang) + to_lang = is_valid_lang(to_lang) + + if not from_lang or not to_lang: + return None + + params['from_lang'] = from_lang + params['to_lang'] = to_lang + params['query'] = query + + return params |