Ver código fonte

Fixed the currency_convert engine.

pyrrh0n1c 7 anos atrás
pai
commit
2231b02add
1 arquivos alterados com 8 adições e 11 exclusões
  1. 8
    11
      searx/engines/currency_convert.py

+ 8
- 11
searx/engines/currency_convert.py Ver arquivo

@@ -10,7 +10,7 @@ if sys.version_info[0] == 3:
10 10
     unicode = str
11 11
 
12 12
 categories = []
13
-url = 'https://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={query}=X'
13
+url = 'https://finance.google.com/finance/converter?a=1&from={0}&to={1}'
14 14
 weight = 100
15 15
 
16 16
 parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
@@ -51,7 +51,7 @@ def request(query, params):
51 51
 
52 52
     q = (from_currency + to_currency).upper()
53 53
 
54
-    params['url'] = url.format(query=q)
54
+    params['url'] = url.format(from_currency, to_currency)
55 55
     params['ammount'] = ammount
56 56
     params['from'] = from_currency
57 57
     params['to'] = to_currency
@@ -63,8 +63,11 @@ def request(query, params):
63 63
 
64 64
 def response(resp):
65 65
     results = []
66
+    pat = '<span class=bld>(.+) {0}</span>'.format(
67
+        resp.search_params['to'].upper())
68
+
66 69
     try:
67
-        _, conversion_rate, _ = resp.text.split(',', 2)
70
+        conversion_rate = re.findall(pat, resp.text)[0]
68 71
         conversion_rate = float(conversion_rate)
69 72
     except:
70 73
         return results
@@ -79,14 +82,8 @@ def response(resp):
79 82
         resp.search_params['to_name'],
80 83
     )
81 84
 
82
-    now_date = datetime.now().strftime('%Y%m%d')
83
-    url = 'https://finance.yahoo.com/currency/converter-results/{0}/{1}-{2}-to-{3}.html'  # noqa
84
-    url = url.format(
85
-        now_date,
86
-        resp.search_params['ammount'],
87
-        resp.search_params['from'].lower(),
88
-        resp.search_params['to'].lower()
89
-    )
85
+    url = 'https://finance.google.com/finance?q={0}{1}'.format(
86
+        resp.search_params['from'].upper(), resp.search_params['to'])
90 87
 
91 88
     results.append({'answer': answer, 'url': url})
92 89