.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.dictzone Namespace Reference

Functions

 request (query, params)
 
 _clean_up_node (node)
 
EngineResults response (resp)
 

Variables

dict about
 
str engine_type = 'online_dictionary'
 
list categories = ['general', 'translate']
 
str base_url = "https://dictzone.com"
 
int weight = 100
 
bool https_support = True
 

Detailed Description

 Dictzone

Function Documentation

◆ _clean_up_node()

searx.engines.dictzone._clean_up_node ( node)
protected

Definition at line 40 of file dictzone.py.

40def _clean_up_node(node):
41 for x in ["./i", "./span", "./button"]:
42 for n in node.xpath(x):
43 n.getparent().remove(n)
44
45

Referenced by response().

+ Here is the caller graph for this function:

◆ request()

searx.engines.dictzone.request ( query,
params )

Definition at line 30 of file dictzone.py.

30def request(query, params): # pylint: disable=unused-argument
31
32 from_lang = params["from_lang"][2] # "english"
33 to_lang = params["to_lang"][2] # "german"
34 query = params["query"]
35
36 params["url"] = f"{base_url}/{from_lang}-{to_lang}-dictionary/{urllib.parse.quote_plus(query)}"
37 return params
38
39

◆ response()

EngineResults searx.engines.dictzone.response ( resp)

Definition at line 46 of file dictzone.py.

46def response(resp) -> EngineResults:
47 results = EngineResults()
48
49 item_list = []
50
51 if not resp.ok:
52 return results
53
54 dom = html.fromstring(resp.text)
55
56 for result in eval_xpath(dom, ".//table[@id='r']//tr"):
57
58 # each row is an Translations.Item
59
60 td_list = result.xpath("./td")
61 if len(td_list) != 2:
62 # ignore header columns "tr/th"
63 continue
64
65 col_from, col_to = td_list
66 _clean_up_node(col_from)
67
68 text = f"{extract_text(col_from)}"
69
70 synonyms = []
71 p_list = col_to.xpath(".//p")
72
73 for i, p_item in enumerate(p_list):
74
75 smpl: str = extract_text(p_list[i].xpath("./i[@class='smpl']")) # type: ignore
76 _clean_up_node(p_item)
77 p_text: str = extract_text(p_item) # type: ignore
78
79 if smpl:
80 p_text += " // " + smpl
81
82 if i == 0:
83 text += f" : {p_text}"
84 continue
85
86 synonyms.append(p_text)
87
88 item = results.types.Translations.Item(text=text, synonyms=synonyms)
89 item_list.append(item)
90
91 # the "autotranslate" of dictzone is loaded by the JS from URL:
92 # https://dictzone.com/trans/hello%20world/en_de
93
94 from_lang = resp.search_params["from_lang"][1] # "en"
95 to_lang = resp.search_params["to_lang"][1] # "de"
96 query = resp.search_params["query"]
97
98 # works only sometimes?
99 autotranslate = http_get(f"{base_url}/trans/{query}/{from_lang}_{to_lang}", timeout=1.0)
100 if autotranslate.ok and autotranslate.text:
101 item_list.insert(0, results.types.Translations.Item(text=autotranslate.text))
102
103 if item_list:
104 results.add(results.types.Translations(translations=item_list, url=resp.search_params["url"]))
105 return results

References _clean_up_node().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.dictzone.about
Initial value:
1= {
2 "website": 'https://dictzone.com/',
3 "wikidata_id": None,
4 "official_api_documentation": None,
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 14 of file dictzone.py.

◆ base_url

str searx.engines.dictzone.base_url = "https://dictzone.com"

Definition at line 25 of file dictzone.py.

◆ categories

list searx.engines.dictzone.categories = ['general', 'translate']

Definition at line 24 of file dictzone.py.

◆ engine_type

str searx.engines.dictzone.engine_type = 'online_dictionary'

Definition at line 23 of file dictzone.py.

◆ https_support

bool searx.engines.dictzone.https_support = True

Definition at line 27 of file dictzone.py.

◆ weight

int searx.engines.dictzone.weight = 100

Definition at line 26 of file dictzone.py.