on master help sign in
Add new engine: SJP
commit6631f1130512f371332242a13a4d0672a70e803f authorPlague Doctor <plague@privacyrequired.com> dateThu 8 Apr 2021, 10:21 (6 years ago) parent5474780
2 files changed+90
searx/engines/sjp.py+82 searx/settings.yml+8
searx/engines/sjp.pynew file+82
@@ -0,0 +1,82 @@
1+# SPDX-License-Identifier: AGPL-3.0-or-later
2+"""Słownik Języka Polskiego (general)
3+
4+"""
5+
6+from lxml.html import fromstring
7+from searx import logger
8+from searx.utils import extract_text
9+from searx.raise_for_httperror import raise_for_httperror
10+
11+logger = logger.getChild('sjp engine')
12+
13+# about
14+about = {
15+ "website": 'https://sjp.pwn.pl',
16+ "wikidata_id": 'Q55117369',
17+ "official_api_documentation": None,
18+ "use_official_api": False,
19+ "require_api_key": False,
20+ "results": 'HTML',
21+}
22+
23+categories = ['general']
24+paging = False
25+
26+URL = 'https://sjp.pwn.pl'
27+SEARCH_URL = URL + '/szukaj/{query}.html'
28+
29+
30+def request(query, params):
31+ params['url'] = SEARCH_URL.format(query=query)
32+ logger.debug(f"query_url --> {params['url']}")
33+ return params
34+
35+
36+def response(resp):
37+ results = []
38+
39+ raise_for_httperror(resp)
40+ dom = fromstring(resp.text)
41+ word = extract_text(dom.xpath('//*[@id="content"]/div/div[1]/div/div[1]/div[1]/div[2]/div/div/div[2]/div/div'))
42+
43+ definitions = []
44+ for src in dom.xpath('//*[@id="content"]/div/div[1]/div/div[1]/div[1]/div[2]/div/div/div/div/div/div'):
45+ src_text = extract_text(src.xpath('./h1/span[@class="entry-head-title"]/text()')).strip()
46+
47+ src_defs = []
48+ for def_item in src.xpath('./div/div[contains(@class, "ribbon-element")]'):
49+ if def_item.xpath('./div[@class="znacz"]'):
50+ sub_defs = []
51+ for def_sub_item in def_item.xpath('./div[@class="znacz"]'):
52+ def_sub_text = extract_text(def_sub_item).lstrip('0123456789. ')
53+ sub_defs.append(def_sub_text)
54+ src_defs.append((word, sub_defs))
55+ else:
56+ def_text = extract_text(def_item).strip()
57+ src_defs.append((def_text, ''))
58+
59+ definitions.append((src_text, src_defs))
60+
61+ if not definitions:
62+ return results
63+
64+ infobox = ''
65+ for src in definitions:
66+ infobox += f"<div><small>{src[0]}</small>"
67+ infobox += "<ul>"
68+ for (def_text, sub_def) in src[1]:
69+ infobox += f"<li>{def_text}</li>"
70+ if sub_def:
71+ infobox += "<ol>"
72+ for sub_def_text in sub_def:
73+ infobox += f"<li>{sub_def_text}</li>"
74+ infobox += "</ol>"
75+ infobox += "</ul></div>"
76+
77+ results.append({
78+ 'infobox': word,
79+ 'content': infobox,
80+ })
81+
82+ return results
searx/settings.yml+8
@@ -1271,6 +1271,14 @@ engines:
12711271 categories: videos
12721272 disabled : True
12731273
1274+ - name: słownik języka polskiego
1275+ engine: sjp
1276+ shortcut: sjp
1277+ base_url: https://sjp.pwn.pl/
1278+ categories: general
1279+ timeout: 5.0
1280+ disabled: True
1281+
12741282# Doku engine lets you access to any Doku wiki instance:
12751283# A public one or a privete/corporate one.
12761284# - name : ubuntuwiki