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