summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/basic_engine.py3
-rw-r--r--searx/engines/duckduckgo.py30
-rw-r--r--searx/engines/filecrop.py1
-rw-r--r--searx/preferences.py2
-rw-r--r--searx/results.py1
-rw-r--r--searx/utils.py1
-rw-r--r--searx/webapp.py1
-rw-r--r--tests/unit/engines/test_duckduckgo.py8
-rw-r--r--tests/unit/test_preferences.py2
-rw-r--r--utils/fabfile.py2
-rw-r--r--utils/fetch_currencies.py23
11 files changed, 46 insertions, 28 deletions
diff --git a/examples/basic_engine.py b/examples/basic_engine.py
index 3428f67fb..c7d02afa6 100644
--- a/examples/basic_engine.py
+++ b/examples/basic_engine.py
@@ -1,5 +1,6 @@
-categories = ['general'] # optional
+categories = ['general'] # optional
+
def request(query, params):
'''pre-request callback
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py
index 373ce1b2d..d29e4416a 100644
--- a/searx/engines/duckduckgo.py
+++ b/searx/engines/duckduckgo.py
@@ -11,13 +11,12 @@
@parse url, title, content
@todo rewrite to api
- @todo language support
- (the current used site does not support language-change)
"""
from urllib import urlencode
from lxml.html import fromstring
from searx.engines.xpath import extract_text
+from searx.languages import language_codes
# engine dependent config
categories = ['general']
@@ -39,13 +38,28 @@ def request(query, params):
offset = (params['pageno'] - 1) * 30
if params['language'] == 'all':
- locale = 'en-us'
+ locale = None
else:
- locale = params['language'].replace('_', '-').lower()
-
- params['url'] = url.format(
- query=urlencode({'q': query, 'kl': locale}),
- offset=offset)
+ locale = params['language'].split('_')
+ if len(locale) == 2:
+ # country code goes first
+ locale = locale[1].lower() + '-' + locale[0].lower()
+ else:
+ # tries to get a country code from language
+ locale = locale[0].lower()
+ lang_codes = [x[0] for x in language_codes]
+ for lc in lang_codes:
+ lc = lc.split('_')
+ if locale == lc[0]:
+ locale = lc[1].lower() + '-' + lc[0].lower()
+ break
+
+ if locale:
+ params['url'] = url.format(
+ query=urlencode({'q': query, 'kl': locale}), offset=offset)
+ else:
+ params['url'] = url.format(
+ query=urlencode({'q': query}), offset=offset)
return params
diff --git a/searx/engines/filecrop.py b/searx/engines/filecrop.py
index 89dc77697..71665bd4e 100644
--- a/searx/engines/filecrop.py
+++ b/searx/engines/filecrop.py
@@ -8,6 +8,7 @@ paging = True
class FilecropResultParser(HTMLParser):
+
def __init__(self):
HTMLParser.__init__(self)
self.__start_processing = False
diff --git a/searx/preferences.py b/searx/preferences.py
index dd9133ddb..e19ae7502 100644
--- a/searx/preferences.py
+++ b/searx/preferences.py
@@ -166,6 +166,7 @@ class SwitchableSetting(Setting):
class EnginesSetting(SwitchableSetting):
+
def _post_init(self):
super(EnginesSetting, self)._post_init()
transformed_choices = []
@@ -191,6 +192,7 @@ class EnginesSetting(SwitchableSetting):
class PluginsSetting(SwitchableSetting):
+
def _post_init(self):
super(PluginsSetting, self)._post_init()
transformed_choices = []
diff --git a/searx/results.py b/searx/results.py
index dcd966ef7..4bb0de0d8 100644
--- a/searx/results.py
+++ b/searx/results.py
@@ -91,6 +91,7 @@ def result_score(result):
class ResultContainer(object):
"""docstring for ResultContainer"""
+
def __init__(self):
super(ResultContainer, self).__init__()
self.results = defaultdict(list)
diff --git a/searx/utils.py b/searx/utils.py
index a444cd3cf..219135a4b 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -74,6 +74,7 @@ def highlight_content(content, query):
class HTMLTextExtractor(HTMLParser):
+
def __init__(self):
HTMLParser.__init__(self)
self.result = []
diff --git a/searx/webapp.py b/searx/webapp.py
index 2093bb0b4..00a203636 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -735,6 +735,7 @@ class ReverseProxyPathFix(object):
:param app: the WSGI application
'''
+
def __init__(self, app):
self.app = app
diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py
index 8f99dc9cb..90cdc9d9e 100644
--- a/tests/unit/engines/test_duckduckgo.py
+++ b/tests/unit/engines/test_duckduckgo.py
@@ -11,16 +11,12 @@ class TestDuckduckgoEngine(SearxTestCase):
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'de_CH'
params = duckduckgo.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
self.assertIn('duckduckgo.com', params['url'])
- self.assertIn('fr-fr', params['url'])
-
- dicto['language'] = 'all'
- params = duckduckgo.request(query, dicto)
- self.assertIn('en-us', params['url'])
+ self.assertIn('ch-de', params['url'])
def test_response(self):
self.assertRaises(AttributeError, duckduckgo.response, None)
diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py
index e418c0af4..c17350809 100644
--- a/tests/unit/test_preferences.py
+++ b/tests/unit/test_preferences.py
@@ -4,6 +4,7 @@ from searx.testing import SearxTestCase
class PluginStub(object):
+
def __init__(self, id, default_on):
self.id = id
self.default_on = default_on
@@ -11,6 +12,7 @@ class PluginStub(object):
class TestSettings(SearxTestCase):
# map settings
+
def test_map_setting_invalid_initialization(self):
with self.assertRaises(MissingArgumentException):
setting = MapSetting(3, wrong_argument={'0': 0})
diff --git a/utils/fabfile.py b/utils/fabfile.py
index 4b356c54a..559e2ab6c 100644
--- a/utils/fabfile.py
+++ b/utils/fabfile.py
@@ -89,7 +89,7 @@ def init():
sudo('git clone https://github.com/asciimoo/searx')
sudo('chown -R {user}:{user} {searx_dir}'.format(user=current_user, searx_dir=searx_dir))
- put(StringIO(uwsgi_file), searx_dir+'/uwsgi.ini')
+ put(StringIO(uwsgi_file), searx_dir + '/uwsgi.ini')
sudo('ln -s {0}/uwsgi.ini /etc/uwsgi/apps-enabled/searx.ini'.format(searx_dir))
run('virtualenv {0}'.format(searx_ve_dir))
diff --git a/utils/fetch_currencies.py b/utils/fetch_currencies.py
index 201b32195..3ca8fcfd7 100644
--- a/utils/fetch_currencies.py
+++ b/utils/fetch_currencies.py
@@ -10,17 +10,17 @@ languages = {'de', 'en', 'es', 'fr', 'hu', 'it', 'nl', 'jp'}
url_template = 'https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&{query}&props=labels%7Cdatatype%7Cclaims%7Caliases&languages=' + '|'.join(languages)
url_wmflabs_template = 'http://wdq.wmflabs.org/api?q='
-url_wikidata_search_template='http://www.wikidata.org/w/api.php?action=query&list=search&format=json&srnamespace=0&srprop=sectiontitle&{query}'
+url_wikidata_search_template = 'http://www.wikidata.org/w/api.php?action=query&list=search&format=json&srnamespace=0&srprop=sectiontitle&{query}'
wmflabs_queries = [
- 'CLAIM[31:8142]', # all devise
+ 'CLAIM[31:8142]', # all devise
]
db = {
- 'iso4217' : {
- },
- 'names' : {
- }
+ 'iso4217': {
+ },
+ 'names': {
+ }
}
@@ -29,7 +29,7 @@ def remove_accents(data):
def normalize_name(name):
- return re.sub(' +',' ', remove_accents(name.lower()).replace('-', ' '))
+ return re.sub(' +', ' ', remove_accents(name.lower()).replace('-', ' '))
def add_currency_name(name, iso4217):
@@ -37,7 +37,6 @@ def add_currency_name(name, iso4217):
db_names = db['names']
-
if not isinstance(iso4217, basestring):
print "problem", name, iso4217
return
@@ -52,7 +51,7 @@ def add_currency_name(name, iso4217):
if iso4217_set is not None and iso4217 not in iso4217_set:
db_names[name].append(iso4217)
else:
- db_names[name] = [ iso4217 ]
+ db_names[name] = [iso4217]
def add_currency_label(label, iso4217, language):
@@ -85,7 +84,7 @@ def parse_currency(data):
labels = data.get('labels', {})
for language in languages:
name = labels.get(language, {}).get('value', None)
- if name != None:
+ if name is not None:
add_currency_name(name, iso4217)
add_currency_label(name, iso4217, language)
@@ -97,7 +96,7 @@ def parse_currency(data):
def fetch_data(wikidata_ids):
- url = url_template.format(query=urlencode({'ids' : '|'.join(wikidata_ids)}))
+ url = url_template.format(query=urlencode({'ids': '|'.join(wikidata_ids)}))
htmlresponse = get(url)
jsonresponse = json.loads(htmlresponse.content)
entities = jsonresponse.get('entities', {})
@@ -127,7 +126,7 @@ def wdq_query(query):
jsonresponse = json.loads(htmlresponse.content)
qlist = map(add_q, jsonresponse.get('items', {}))
error = jsonresponse.get('status', {}).get('error', None)
- if error != None and error != 'OK':
+ if error is not None and error != 'OK':
print "error for query '" + query + "' :" + error
fetch_data_batch(qlist)