summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2017-11-07 16:05:43 +0100
committerGitHub <noreply@github.com>2017-11-07 16:05:43 +0100
commitd00aaeedfac7b86cbcb82e352d2f92438083e4c2 (patch)
tree0fc05c9acc76b779280f91677b79b8d54ec35580 /searx
parent00a7041daa7e1f4de1ca7b8787005f571c1f0a65 (diff)
parenta1d1a50149b76545086fd2639ff58797007e435e (diff)
downloadsearxng-d00aaeedfac7b86cbcb82e352d2f92438083e4c2.tar.gz
searxng-d00aaeedfac7b86cbcb82e352d2f92438083e4c2.zip
Merge pull request #1079 from pyrrh0n1c/master
Fixed the currency_convert engine.
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/currency_convert.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py
index 1218d4849..1bb4e60c9 100644
--- a/searx/engines/currency_convert.py
+++ b/searx/engines/currency_convert.py
@@ -10,7 +10,7 @@ if sys.version_info[0] == 3:
unicode = str
categories = []
-url = 'https://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={query}=X'
+url = 'https://finance.google.com/finance/converter?a=1&from={0}&to={1}'
weight = 100
parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
@@ -44,15 +44,15 @@ def request(query, params):
# wrong query
return params
- ammount, from_currency, to_currency = m.groups()
- ammount = float(ammount)
+ amount, from_currency, to_currency = m.groups()
+ amount = float(amount)
from_currency = name_to_iso4217(from_currency.strip())
to_currency = name_to_iso4217(to_currency.strip())
q = (from_currency + to_currency).upper()
- params['url'] = url.format(query=q)
- params['ammount'] = ammount
+ params['url'] = url.format(from_currency, to_currency)
+ params['amount'] = amount
params['from'] = from_currency
params['to'] = to_currency
params['from_name'] = iso4217_to_name(from_currency, 'en')
@@ -63,30 +63,27 @@ def request(query, params):
def response(resp):
results = []
+ pat = '<span class=bld>(.+) {0}</span>'.format(
+ resp.search_params['to'].upper())
+
try:
- _, conversion_rate, _ = resp.text.split(',', 2)
+ conversion_rate = re.findall(pat, resp.text)[0]
conversion_rate = float(conversion_rate)
except:
return results
answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
- resp.search_params['ammount'],
+ resp.search_params['amount'],
resp.search_params['from'],
- resp.search_params['ammount'] * conversion_rate,
+ resp.search_params['amount'] * conversion_rate,
resp.search_params['to'],
conversion_rate,
resp.search_params['from_name'],
resp.search_params['to_name'],
)
- now_date = datetime.now().strftime('%Y%m%d')
- url = 'https://finance.yahoo.com/currency/converter-results/{0}/{1}-{2}-to-{3}.html' # noqa
- url = url.format(
- now_date,
- resp.search_params['ammount'],
- resp.search_params['from'].lower(),
- resp.search_params['to'].lower()
- )
+ url = 'https://finance.google.com/finance?q={0}{1}'.format(
+ resp.search_params['from'].upper(), resp.search_params['to'])
results.append({'answer': answer, 'url': url})