summaryrefslogtreecommitdiff
path: root/searx/engines/brave.py
diff options
context:
space:
mode:
authorMarkus <markus@venom.fritz.box>2024-09-15 12:22:06 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-09-15 12:48:35 +0200
commitcdb4927b8ba0aec61ae169b9e9b54a7e8f2f0e9f (patch)
treec3038e8e4f8622c2a9df9dc61894c5b95bc10d7f /searx/engines/brave.py
parent84e2f9d46a7aada4347df7f4a79147170cc31dc0 (diff)
downloadsearxng-cdb4927b8ba0aec61ae169b9e9b54a7e8f2f0e9f.tar.gz
searxng-cdb4927b8ba0aec61ae169b9e9b54a7e8f2f0e9f.zip
[fix] fetch_traits: brave, google, annas_archive & radio_browser
This patch fixes a bug reported by CI "Fetch traits" [1] (brave) and improves other fetch traits functions (google, annas_archive & radio_browser). brave: File "/home/runner/work/searxng/searxng/searx/engines/brave.py", line 434, in fetch_traits sxng_tag = region_tag(babel.Locale.parse(ui_lang, sep='-')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/runner/work/searxng/searxng/searx/locales.py", line 155, in region_tag Error: raise ValueError('%s missed a territory') google: change ERROR message about unknow UI language to INFO message radio_browser: country_list contains duplicates that differ only in upper/lower case annas_archive: for better diff; sort the persistence of the traits [1] https://github.com/searxng/searxng/actions/runs/10606312371/job/29433352518#step:6:41 Signed-off-by: Markus <markus@venom.fritz.box>
Diffstat (limited to 'searx/engines/brave.py')
-rw-r--r--searx/engines/brave.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/searx/engines/brave.py b/searx/engines/brave.py
index 4c43386ed..6f7e342e7 100644
--- a/searx/engines/brave.py
+++ b/searx/engines/brave.py
@@ -430,7 +430,8 @@ def fetch_traits(engine_traits: EngineTraits):
ui_lang = option.get('value')
try:
- if '-' in ui_lang and not ui_lang.startswith("zh-"):
+ l = babel.Locale.parse(ui_lang, sep='-')
+ if l.territory:
sxng_tag = region_tag(babel.Locale.parse(ui_lang, sep='-'))
else:
sxng_tag = language_tag(babel.Locale.parse(ui_lang, sep='-'))
@@ -453,7 +454,7 @@ def fetch_traits(engine_traits: EngineTraits):
if not resp.ok: # type: ignore
print("ERROR: response from Brave is not OK.")
- country_js = resp.text[resp.text.index("options:{all") + len('options:') :]
+ country_js = resp.text[resp.text.index("options:{all") + len('options:') :] # type: ignore
country_js = country_js[: country_js.index("},k={default")]
country_tags = js_variable_to_python(country_js)