diff options
author | Johannes Schauer <josch@debian.org> | 2017-11-24 10:58:21 +0100 |
---|---|---|
committer | Johannes Schauer <josch@debian.org> | 2017-11-24 10:58:21 +0100 |
commit | 6479b263d1fd25f5db5228e0360966b285dfa8b3 (patch) | |
tree | 1917ef9846e45cd386a3f4b77693441063c7dba6 /utils | |
parent | 73ebd8743faa9b30a6a8f3f39261978c5be99479 (diff) |
New upstream version 0.13.1+dfsg1
Diffstat (limited to 'utils')
-rw-r--r-- | utils/fetch_currencies.py | 8 | ||||
-rw-r--r-- | utils/fetch_languages.py | 16 | ||||
-rwxr-xr-x | utils/standalone_searx.py | 5 | ||||
-rwxr-xr-x | utils/update-translations.sh | 6 |
4 files changed, 20 insertions, 15 deletions
diff --git a/utils/fetch_currencies.py b/utils/fetch_currencies.py index 716b505..5605fb3 100644 --- a/utils/fetch_currencies.py +++ b/utils/fetch_currencies.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import print_function + import json import re import unicodedata @@ -38,13 +40,13 @@ def add_currency_name(name, iso4217): db_names = db['names'] if not isinstance(iso4217, basestring): - print "problem", name, iso4217 + print("problem", name, iso4217) return name = normalize_name(name) if name == '': - print "name empty", iso4217 + print("name empty", iso4217) return iso4217_set = db_names.get(name, None) @@ -127,7 +129,7 @@ def wdq_query(query): qlist = map(add_q, jsonresponse.get('items', {})) error = jsonresponse.get('status', {}).get('error', None) if error is not None and error != 'OK': - print "error for query '" + query + "' :" + error + print("error for query '" + query + "' :" + error) fetch_data_batch(qlist) diff --git a/utils/fetch_languages.py b/utils/fetch_languages.py index 3241370..424f400 100644 --- a/utils/fetch_languages.py +++ b/utils/fetch_languages.py @@ -8,13 +8,13 @@ # are written in current directory to avoid overwriting in case something goes wrong. from requests import get -from urllib import urlencode from lxml.html import fromstring -from json import loads, dumps +from json import loads, dump import io from sys import path path.append('../searx') # noqa from searx import settings +from searx.url_utils import urlencode from searx.engines import initialize_engines, engines # Geonames API for country names. @@ -70,7 +70,7 @@ def get_country_name(locale): json = loads(response.text) content = json.get('geonames', None) if content is None or len(content) != 1: - print "No country name found for " + locale[0] + "-" + locale[1] + print("No country name found for " + locale[0] + "-" + locale[1]) return '' return content[0].get('countryName', '') @@ -84,11 +84,11 @@ def fetch_supported_languages(): try: engines_languages[engine_name] = engines[engine_name].fetch_supported_languages() except Exception as e: - print e + print(e) # write json file with io.open(engines_languages_file, "w", encoding="utf-8") as f: - f.write(unicode(dumps(engines_languages, ensure_ascii=False, encoding="utf-8"))) + dump(engines_languages, f, ensure_ascii=False) # Join all language lists. @@ -97,7 +97,7 @@ def join_language_lists(): global languages # include wikipedia first for more accurate language names languages = {code: lang for code, lang - in engines_languages['wikipedia'].iteritems() + in engines_languages['wikipedia'].items() if valid_code(code)} for engine_name in engines_languages: @@ -121,7 +121,7 @@ def join_language_lists(): # filter list to include only languages supported by most engines min_supported_engines = int(0.70 * len(engines_languages)) languages = {code: lang for code, lang - in languages.iteritems() + in languages.items() if len(lang.get('counter', [])) >= min_supported_engines or len(languages.get(code.split('-')[0], {}).get('counter', [])) >= min_supported_engines} @@ -165,7 +165,7 @@ def filter_single_country_languages(): # Write languages.py. def write_languages_file(): - new_file = open(languages_file, 'w') + new_file = open(languages_file, 'wb') file_content = '# -*- coding: utf-8 -*-\n'\ + '# list of language codes\n'\ + '# this file is generated automatically by utils/update_search_languages.py\n'\ diff --git a/utils/standalone_searx.py b/utils/standalone_searx.py index b19df4b..2231636 100755 --- a/utils/standalone_searx.py +++ b/utils/standalone_searx.py @@ -25,6 +25,8 @@ path.append(realpath(dirname(realpath(__file__)) + '/../')) # initialization from json import dumps from searx import settings +import sys +import codecs import searx.query import searx.search import searx.engines @@ -97,5 +99,6 @@ result_container_json = { "paging": result_container.paging, "results_number": result_container.results_number() } +sys.stdout = codecs.getwriter("UTF-8")(sys.stdout) +sys.stdout.write(dumps(result_container_json, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf-8", default=json_serial)) -print(dumps(result_container_json, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf-8", default=json_serial)) diff --git a/utils/update-translations.sh b/utils/update-translations.sh index 00e7fb1..240387a 100755 --- a/utils/update-translations.sh +++ b/utils/update-translations.sh @@ -7,9 +7,9 @@ SEARX_DIR='searx' -pybabel extract -F babel.cfg -o messages.pot $SEARX_DIR -for f in `ls $SEARX_DIR'/translations/'`; do - pybabel update -N -i messages.pot -d $SEARX_DIR'/translations/' -l $f +pybabel extract -F babel.cfg -o messages.pot "$SEARX_DIR" +for f in `ls "$SEARX_DIR"'/translations/'`; do + pybabel update -N -i messages.pot -d "$SEARX_DIR"'/translations/' -l "$f" done echo '[!] update done, edit .po files if required and run pybabel compile -d searx/translations/' |