diff options
Diffstat (limited to 'searx/engines/currency_convert.py')
-rw-r--r-- | searx/engines/currency_convert.py | 29 |
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}) |