|
@@ -11,7 +11,7 @@ if sys.version_info[0] == 3:
|
11
|
11
|
unicode = str
|
12
|
12
|
|
13
|
13
|
categories = []
|
14
|
|
-url = 'https://finance.google.com/finance/converter?a=1&from={0}&to={1}'
|
|
14
|
+url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
|
15
|
15
|
weight = 100
|
16
|
16
|
|
17
|
17
|
parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
|
|
@@ -63,16 +63,13 @@ def request(query, params):
|
63
|
63
|
|
64
|
64
|
|
65
|
65
|
def response(resp):
|
|
66
|
+ """remove first and last lines to get only json"""
|
|
67
|
+ json_resp = resp.text[resp.text.find('\n')+1:resp.text.rfind('\n')-2]
|
66
|
68
|
results = []
|
67
|
|
- pat = '<span class=bld>(.+) {0}</span>'.format(
|
68
|
|
- resp.search_params['to'].upper())
|
69
|
|
-
|
70
|
69
|
try:
|
71
|
|
- conversion_rate = re.findall(pat, resp.text)[0]
|
72
|
|
- conversion_rate = float(conversion_rate)
|
|
70
|
+ conversion_rate = float(json.loads(json_resp)['conversion']['converted-amount'])
|
73
|
71
|
except:
|
74
|
72
|
return results
|
75
|
|
-
|
76
|
73
|
answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
|
77
|
74
|
resp.search_params['amount'],
|
78
|
75
|
resp.search_params['from'],
|
|
@@ -83,7 +80,7 @@ def response(resp):
|
83
|
80
|
resp.search_params['to_name'],
|
84
|
81
|
)
|
85
|
82
|
|
86
|
|
- url = 'https://finance.google.com/finance?q={0}{1}'.format(
|
|
83
|
+ url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'.format(
|
87
|
84
|
resp.search_params['from'].upper(), resp.search_params['to'])
|
88
|
85
|
|
89
|
86
|
results.append({'answer': answer, 'url': url})
|