159def fetch_traits(engine_traits: EngineTraits):
160 """Fetch languages from yahoo"""
161
162
163 import babel
164 from searx import network
166
167 engine_traits.all_locale = 'any'
168
169 resp = network.get('https://search.yahoo.com/preferences/languages')
170 if not resp.ok:
171 print("ERROR: response from yahoo is not OK.")
172
173 dom = html.fromstring(resp.text)
174 offset = len('lang_')
175
176 eng2sxng = {'zh_chs': 'zh_Hans', 'zh_cht': 'zh_Hant'}
177
178 for val in eval_xpath_list(dom, '//div[contains(@class, "lang-item")]/input/@value'):
179 eng_tag = val[offset:]
180
181 try:
182 sxng_tag = language_tag(babel.Locale.parse(eng2sxng.get(eng_tag, eng_tag)))
183 except babel.UnknownLocaleError:
184 print('ERROR: unknown language --> %s' % eng_tag)
185 continue
186
187 conflict = engine_traits.languages.get(sxng_tag)
188 if conflict:
189 if conflict != eng_tag:
190 print("CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
191 continue
192 engine_traits.languages[sxng_tag] = eng_tag