diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-04 12:11:58 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-04 12:11:58 +0100 |
commit | 9f1cb7a943cc5a5e26fec753ddeec47bd3580ea0 (patch) | |
tree | 7b3a571ab8caad931b4cbcdf063bf8b10c715095 /utils | |
parent | 3cb7daedb7c5c93a98dfefa191c161f31a1347c6 (diff) | |
parent | a5d3585a0c47b736b0845fcf6786f0f5b57d4215 (diff) | |
download | searxng-9f1cb7a943cc5a5e26fec753ddeec47bd3580ea0.tar.gz searxng-9f1cb7a943cc5a5e26fec753ddeec47bd3580ea0.zip |
Merge branch 'master' of https://github.com/asciimoo/searx into filtron
Diffstat (limited to 'utils')
-rw-r--r-- | utils/fetch_languages.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/utils/fetch_languages.py b/utils/fetch_languages.py index a6af07303..ddebb4111 100644 --- a/utils/fetch_languages.py +++ b/utils/fetch_languages.py @@ -5,7 +5,7 @@ # Output files (engines_languages.json and languages.py) # are written in current directory to avoid overwriting in case something goes wrong. -from json import dump +import json import io from sys import path from babel import Locale, UnknownLocaleError @@ -22,19 +22,22 @@ languages_file = 'languages.py' # Fetchs supported languages for each engine and writes json file with those. def fetch_supported_languages(): + engines_languages = {} - for engine_name in engines: + names = list(engines) + names.sort() + + for engine_name in names: + print("fetching languages of engine %s" % engine_name) + if hasattr(engines[engine_name], 'fetch_supported_languages'): - try: - engines_languages[engine_name] = engines[engine_name].fetch_supported_languages() - if type(engines_languages[engine_name]) == list: - engines_languages[engine_name] = sorted(engines_languages[engine_name]) - except Exception as e: - print(e) + engines_languages[engine_name] = engines[engine_name].fetch_supported_languages() + if type(engines_languages[engine_name]) == list: + engines_languages[engine_name] = sorted(engines_languages[engine_name]) # write json file - with io.open(engines_languages_file, "w", encoding="utf-8") as f: - dump(engines_languages, f, ensure_ascii=False, indent=4, separators=(',', ': ')) + with open(engines_languages_file, 'w', encoding='utf-8') as f: + json.dump(engines_languages, f, indent=2, sort_keys=True) return engines_languages |