116 params[
"method"] =
"GET"
119 "engine": leta_engine,
120 "x-sveltekit-invalidated":
"001",
123 country = traits.get_region(params.get(
"searxng_locale"), traits.all_locale)
125 args[
"country"] = country
127 language = traits.get_language(params.get(
"searxng_locale"), traits.all_locale)
129 args[
"language"] = language
131 if params[
"time_range"]
in time_range_dict:
132 args[
"lastUpdated"] = time_range_dict[params[
"time_range"]]
134 if params[
"pageno"] > 1:
135 args[
"page"] = params[
"pageno"]
137 params[
"url"] = f
"{search_url}/search/__data.json?{urlencode(args)}"
143 json_response = resp.json()
145 nodes = json_response[
"nodes"]
150 data_nodes = nodes[2][
"data"]
158 query_meta_data: DataNodeQueryMetaDataIndices = data_nodes[0]
160 query_items_indices = query_meta_data[
"items"]
163 for idx
in data_nodes[query_items_indices]:
164 query_item_indices: DataNodeResultIndices = data_nodes[idx]
167 url=data_nodes[query_item_indices[
"link"]],
168 title=data_nodes[query_item_indices[
"title"]],
169 content=data_nodes[query_item_indices[
"snippet"]],
177 """Fetch languages and regions from Mullvad-Leta"""
179 def extract_table_data(table):
180 for row
in table.xpath(
".//tr")[2:]:
181 cells = row.xpath(
".//td | .//th")
183 cell0 = cells[0].text_content().strip()
184 cell1 = cells[1].text_content().strip()
193 resp = http_get(f
"{search_url}/documentation")
194 if not isinstance(resp, Response):
195 print(
"ERROR: failed to get response from mullvad-leta. Are you connected to the VPN?")
198 print(
"ERROR: response from mullvad-leta is not OK. Are you connected to the VPN?")
201 dom = html.fromstring(resp.text)
208 tables = eval_xpath_list(dom.body,
"//table")
209 if tables
is None or len(tables) <= 0:
210 print(
"ERROR: could not find any tables. Was the page updated?")
212 language_table = tables[3]
214 "zh-hant":
"zh_Hans",
215 "zh-hans":
"zh_Hant",
219 for language, code
in extract_table_data(language_table):
221 locale_tag = lang_map.get(code, code).replace(
"-",
"_")
223 locale = babel.Locale.parse(locale_tag)
224 except babel.UnknownLocaleError:
225 print(f
"ERROR: Mullvad-Leta language {language} ({code}) is unknown by babel")
228 sxng_tag = language_tag(locale)
229 engine_traits.languages[sxng_tag] = code
231 country_table = tables[2]
242 for country, code
in extract_table_data(country_table):
244 sxng_tag = country_map.get(code)
246 engine_traits.regions[sxng_tag] = code
250 locale = babel.Locale.parse(f
"{code.lower()}_{code.upper()}")
251 except babel.UnknownLocaleError:
255 engine_traits.regions[region_tag(locale)] = code
258 official_locales = get_official_locales(code, engine_traits.languages.keys(), regional=
True)
259 if not official_locales:
260 print(f
"ERROR: Mullvad-Leta country '{code}' ({country}) could not be mapped as expected.")
263 for locale
in official_locales:
264 engine_traits.regions[region_tag(locale)] = code