diff options
| -rw-r--r-- | README.rst | 2 | ||||
| -rw-r--r-- | searx/engines/currency_convert.py | 6 | ||||
| -rw-r--r-- | searx/poolrequests.py | 12 | ||||
| -rw-r--r-- | searx/preferences.py | 2 | ||||
| -rw-r--r-- | searx/settings.yml | 2 | ||||
| -rw-r--r-- | tests/unit/engines/test_currency_convert.py | 17 |
6 files changed, 22 insertions, 19 deletions
diff --git a/README.rst b/README.rst index c0993157d..6563fe8ab 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,7 @@ Installation ``git clone git@github.com:asciimoo/searx.git && cd searx`` - install dependencies: ``./manage.sh update_packages`` - edit your - `settings.yml <https://github.com/asciimoo/searx/blob/master/settings.yml>`__ + `settings.yml <https://github.com/asciimoo/searx/blob/master/searx/settings.yml>`__ (set your ``secret_key``!) - run ``python searx/webapp.py`` to start the application diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py index bdcd8f711..b0ffb490a 100644 --- a/searx/engines/currency_convert.py +++ b/searx/engines/currency_convert.py @@ -9,13 +9,13 @@ categories = [] url = 'https://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={query}=X' weight = 100 -parser_re = re.compile(u'.*?(\d+(?:\.\d+)?) ([^.0-9].+) (in|to) ([^\.]+)\W*$', re.I) # noqa +parser_re = re.compile(u'.*?(\d+(?:\.\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I) # noqa db = 1 def normalize_name(name): - name = name.lower().replace('-', ' ') + name = name.lower().replace('-', ' ').rstrip('s') name = re.sub(' +', ' ', name) return unicodedata.normalize('NFKD', name).lower() @@ -40,7 +40,7 @@ def request(query, params): # wrong query return params - ammount, from_currency, none, to_currency = m.groups() + ammount, from_currency, to_currency = m.groups() ammount = float(ammount) from_currency = name_to_iso4217(from_currency.strip()) to_currency = name_to_iso4217(to_currency.strip()) diff --git a/searx/poolrequests.py b/searx/poolrequests.py index 13c6a906e..f268df207 100644 --- a/searx/poolrequests.py +++ b/searx/poolrequests.py @@ -41,14 +41,18 @@ class HTTPAdapterWithConnParams(requests.adapters.HTTPAdapter): block=self._pool_block, **self._conn_params) +connect = settings['outgoing'].get('pool_connections', 100) # Magic number kept from previous code +maxsize = settings['outgoing'].get('pool_maxsize', requests.adapters.DEFAULT_POOLSIZE) # Picked from constructor if settings['outgoing'].get('source_ips'): - http_adapters = cycle(HTTPAdapterWithConnParams(pool_connections=100, source_address=(source_ip, 0)) + http_adapters = cycle(HTTPAdapterWithConnParams(pool_connections=connect, pool_maxsize=maxsize, + source_address=(source_ip, 0)) for source_ip in settings['outgoing']['source_ips']) - https_adapters = cycle(HTTPAdapterWithConnParams(pool_connections=100, source_address=(source_ip, 0)) + https_adapters = cycle(HTTPAdapterWithConnParams(pool_connections=connect, pool_maxsize=maxsize, + source_address=(source_ip, 0)) for source_ip in settings['outgoing']['source_ips']) else: - http_adapters = cycle((HTTPAdapterWithConnParams(pool_connections=100), )) - https_adapters = cycle((HTTPAdapterWithConnParams(pool_connections=100), )) + http_adapters = cycle((HTTPAdapterWithConnParams(pool_connections=connect, pool_maxsize=maxsize), )) + https_adapters = cycle((HTTPAdapterWithConnParams(pool_connections=connect, pool_maxsize=maxsize), )) class SessionSinglePool(requests.Session): diff --git a/searx/preferences.py b/searx/preferences.py index ad9e67335..a87cd5029 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -181,7 +181,7 @@ class EnginesSetting(SwitchableSetting): return [item[len('engine_'):].replace('_', ' ').replace(' ', '__') for item in items] def transform_values(self, values): - if len(values) == 1 and values[0] == '': + if len(values) == 1 and next(iter(values)) == '': return list() transformed_values = [] for value in values: diff --git a/searx/settings.yml b/searx/settings.yml index ff85684ac..96455fc23 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -21,6 +21,8 @@ ui: outgoing: # communication with search engines request_timeout : 2.0 # seconds useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator + pool_connections : 100 # Number of different hosts + pool_maxsize : 10 # Number of simultaneous requests by host # uncomment below section if you want to use a proxy # see http://docs.python-requests.org/en/latest/user/advanced/#proxies # SOCKS proxies are not supported : see https://github.com/kennethreitz/requests/pull/478 diff --git a/tests/unit/engines/test_currency_convert.py b/tests/unit/engines/test_currency_convert.py index 84ec3b742..b7720569f 100644 --- a/tests/unit/engines/test_currency_convert.py +++ b/tests/unit/engines/test_currency_convert.py @@ -14,23 +14,19 @@ class TestCurrencyConvertEngine(SearxTestCase): params = currency_convert.request(query, dicto) self.assertNotIn('url', params) - query = '1.1.1 EUR in USD' - params = currency_convert.request(query, dicto) - self.assertNotIn('url', params) - - query = '10 eur in usd' + query = 'convert 10 Pound Sterlings to United States Dollars' params = currency_convert.request(query, dicto) self.assertIn('url', params) self.assertIn('finance.yahoo.com', params['url']) - self.assertIn('EUR', params['url']) + self.assertIn('GBP', params['url']) self.assertIn('USD', params['url']) def test_response(self): dicto = defaultdict(dict) dicto['ammount'] = float(10) - dicto['from'] = "EUR" + dicto['from'] = "GBP" dicto['to'] = "USD" - dicto['from_name'] = "euro" + dicto['from_name'] = "pound sterling" dicto['to_name'] = "United States dollar" response = mock.Mock(text='a,b,c,d', search_params=dicto) self.assertEqual(currency_convert.response(response), []) @@ -40,7 +36,8 @@ class TestCurrencyConvertEngine(SearxTestCase): results = currency_convert.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) - self.assertEqual(results[0]['answer'], '10.0 EUR = 5.0 USD, 1 EUR (euro) = 0.5 USD (United States dollar)') + self.assertEqual(results[0]['answer'], '10.0 GBP = 5.0 USD, 1 GBP (pound sterling)' + + ' = 0.5 USD (United States dollar)') now_date = datetime.now().strftime('%Y%m%d') self.assertEqual(results[0]['url'], 'https://finance.yahoo.com/currency/converter-results/' + - now_date + '/10.0-eur-to-usd.html') + now_date + '/10.0-gbp-to-usd.html') |