summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2018-04-23 14:08:58 +0200
committerGitHub <noreply@github.com>2018-04-23 14:08:58 +0200
commit5f3ada4721831b5dee5db2704cfcb45fdfda04db (patch)
treef59b94c99b04735c0c51940bae861c6fd9e5e273 /searx/engines
parent829d4793125b9214f9c80c807807343783b4715b (diff)
parent06e070aee26a432f176b19c91fb8bae3553415d7 (diff)
downloadsearxng-5f3ada4721831b5dee5db2704cfcb45fdfda04db.tar.gz
searxng-5f3ada4721831b5dee5db2704cfcb45fdfda04db.zip
Merge pull request #1279 from rinpatch/duckduckgo-currency
Switched currency converter to duckduckgo and added Bitcoin to currency list
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/currency_convert.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py
index 9c1c2f7b3..8eab8f673 100644
--- a/searx/engines/currency_convert.py
+++ b/searx/engines/currency_convert.py
@@ -11,7 +11,7 @@ if sys.version_info[0] == 3:
unicode = str
categories = []
-url = 'https://finance.google.com/finance/converter?a=1&from={0}&to={1}'
+url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
weight = 100
parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
@@ -44,7 +44,6 @@ def request(query, params):
if not m:
# wrong query
return params
-
amount, from_currency, to_currency = m.groups()
amount = float(amount)
from_currency = name_to_iso4217(from_currency.strip())
@@ -63,16 +62,13 @@ def request(query, params):
def response(resp):
+ """remove first and last lines to get only json"""
+ json_resp = resp.text[resp.text.find('\n') + 1:resp.text.rfind('\n') - 2]
results = []
- pat = '<span class=bld>(.+) {0}</span>'.format(
- resp.search_params['to'].upper())
-
try:
- conversion_rate = re.findall(pat, resp.text)[0]
- conversion_rate = float(conversion_rate)
+ conversion_rate = float(json.loads(json_resp)['conversion']['converted-amount'])
except:
return results
-
answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
resp.search_params['amount'],
resp.search_params['from'],
@@ -83,7 +79,7 @@ def response(resp):
resp.search_params['to_name'],
)
- url = 'https://finance.google.com/finance?q={0}{1}'.format(
+ url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'.format(
resp.search_params['from'].upper(), resp.search_params['to'])
results.append({'answer': answer, 'url': url})