93def fetch_traits(engine_traits: EngineTraits):
94 """Fetch languages from Archlinux-Wiki. The location of the Wiki address of a
95 language is mapped in a :py:obj:`custom field
96 <searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``). Depending
97 on the location, the ``title`` argument in the request is translated.
98
99 .. code:: python
100
101 "custom": {
102 "wiki_netloc": {
103 "de": "wiki.archlinux.de",
104 # ...
105 "zh": "wiki.archlinuxcn.org"
106 }
107 "title": {
108 "de": "Spezial:Suche",
109 # ...
110 "zh": "Special:\u641c\u7d22"
111 },
112 },
113
114 """
115
117
118 engine_traits.custom['wiki_netloc'] = {}
119 engine_traits.custom['title'] = {}
120
121 title_map = {
122 'de': 'Spezial:Suche',
123 'fa': 'ویژه:جستجو',
124 'ja': '特別:検索',
125 'zh': 'Special:搜索',
126 }
127
128 resp = get('https://wiki.archlinux.org/')
129 if not resp.ok:
130 print("ERROR: response from wiki.archlinux.org is not OK.")
131
132 dom = lxml.html.fromstring(resp.text)
133 for a in eval_xpath_list(dom, "//a[@class='interlanguage-link-target']"):
134
135 sxng_tag = language_tag(babel.Locale.parse(a.get('lang'), sep='-'))
136
137 sxng_tag = sxng_tag.split('_')[0]
138
139 netloc = urlparse(a.get('href')).netloc
140 if netloc != 'wiki.archlinux.org':
141 title = title_map.get(sxng_tag)
142 if not title:
143 print("ERROR: title tag from %s (%s) is unknown" % (netloc, sxng_tag))
144 continue
145 engine_traits.custom['wiki_netloc'][sxng_tag] = netloc
146 engine_traits.custom['title'][sxng_tag] = title
147
148 eng_tag = extract_text(eval_xpath_list(a, ".//span"))
149 engine_traits.languages[sxng_tag] = eng_tag
150
151 engine_traits.languages['en'] = 'English'