125 params[
"method"] =
"GET"
128 "engine": leta_engine,
129 "x-sveltekit-invalidated":
"001",
132 country = traits.get_region(params.get(
"searxng_locale"), traits.all_locale)
134 args[
"country"] = country
136 language = traits.get_language(params.get(
"searxng_locale"), traits.all_locale)
138 args[
"language"] = language
140 if params[
"time_range"]
in time_range_dict:
141 args[
"lastUpdated"] = time_range_dict[params[
"time_range"]]
143 if params[
"pageno"] > 1:
144 args[
"page"] = params[
"pageno"]
146 params[
"url"] = f
"{search_url}/search/__data.json?{urlencode(args)}"
152 json_response = resp.json()
154 nodes = json_response[
"nodes"]
159 data_nodes = nodes[2][
"data"]
167 query_meta_data: DataNodeQueryMetaDataIndices = data_nodes[0]
169 query_items_indices = query_meta_data[
"items"]
172 for idx
in data_nodes[query_items_indices]:
173 query_item_indices: DataNodeResultIndices = data_nodes[idx]
176 url=data_nodes[query_item_indices[
"link"]],
177 title=data_nodes[query_item_indices[
"title"]],
178 content=data_nodes[query_item_indices[
"snippet"]],
186 """Fetch languages and regions from Mullvad-Leta"""
188 def extract_table_data(table):
189 for row
in table.xpath(
".//tr")[2:]:
190 cells = row.xpath(
".//td | .//th")
192 cell0 = cells[0].text_content().strip()
193 cell1 = cells[1].text_content().strip()
202 resp = http_get(f
"{search_url}/documentation")
203 if not isinstance(resp, Response):
204 print(
"ERROR: failed to get response from mullvad-leta. Are you connected to the VPN?")
207 print(
"ERROR: response from mullvad-leta is not OK. Are you connected to the VPN?")
210 dom = html.fromstring(resp.text)
217 tables = eval_xpath_list(dom.body,
"//table")
218 if tables
is None or len(tables) <= 0:
219 print(
"ERROR: could not find any tables. Was the page updated?")
221 language_table = tables[3]
223 "zh-hant":
"zh_Hans",
224 "zh-hans":
"zh_Hant",
228 for language, code
in extract_table_data(language_table):
230 locale_tag = lang_map.get(code, code).replace(
"-",
"_")
232 locale = babel.Locale.parse(locale_tag)
233 except babel.UnknownLocaleError:
234 print(f
"ERROR: Mullvad-Leta language {language} ({code}) is unknown by babel")
237 sxng_tag = language_tag(locale)
238 engine_traits.languages[sxng_tag] = code
240 country_table = tables[2]
251 for country, code
in extract_table_data(country_table):
253 sxng_tag = country_map.get(code)
255 engine_traits.regions[sxng_tag] = code
259 locale = babel.Locale.parse(f
"{code.lower()}_{code.upper()}")
260 except babel.UnknownLocaleError:
264 engine_traits.regions[region_tag(locale)] = code
267 official_locales = get_official_locales(code, engine_traits.languages.keys(), regional=
True)
268 if not official_locales:
269 print(f
"ERROR: Mullvad-Leta country '{code}' ({country}) could not be mapped as expected.")
272 for locale
in official_locales:
273 engine_traits.regions[region_tag(locale)] = code