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