Browse Source

Fixed the currency_convert engine.

pyrrh0n1c 7 years ago
parent
commit
2231b02add
1 changed files with 8 additions and 11 deletions
  1. 8
    11
      searx/engines/currency_convert.py

+ 8
- 11
searx/engines/currency_convert.py View File

10
     unicode = str
10
     unicode = str
11
 
11
 
12
 categories = []
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
 weight = 100
14
 weight = 100
15
 
15
 
16
 parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
16
 parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
51
 
51
 
52
     q = (from_currency + to_currency).upper()
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
     params['ammount'] = ammount
55
     params['ammount'] = ammount
56
     params['from'] = from_currency
56
     params['from'] = from_currency
57
     params['to'] = to_currency
57
     params['to'] = to_currency
63
 
63
 
64
 def response(resp):
64
 def response(resp):
65
     results = []
65
     results = []
66
+    pat = '<span class=bld>(.+) {0}</span>'.format(
67
+        resp.search_params['to'].upper())
68
+
66
     try:
69
     try:
67
-        _, conversion_rate, _ = resp.text.split(',', 2)
70
+        conversion_rate = re.findall(pat, resp.text)[0]
68
         conversion_rate = float(conversion_rate)
71
         conversion_rate = float(conversion_rate)
69
     except:
72
     except:
70
         return results
73
         return results
79
         resp.search_params['to_name'],
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
     results.append({'answer': answer, 'url': url})
88
     results.append({'answer': answer, 'url': url})
92
 
89