|
@@ -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)
|
|
@@ -44,15 +44,15 @@ def request(query, params):
|
44
|
44
|
# wrong query
|
45
|
45
|
return params
|
46
|
46
|
|
47
|
|
- ammount, from_currency, to_currency = m.groups()
|
48
|
|
- ammount = float(ammount)
|
|
47
|
+ amount, from_currency, to_currency = m.groups()
|
|
48
|
+ amount = float(amount)
|
49
|
49
|
from_currency = name_to_iso4217(from_currency.strip())
|
50
|
50
|
to_currency = name_to_iso4217(to_currency.strip())
|
51
|
51
|
|
52
|
52
|
q = (from_currency + to_currency).upper()
|
53
|
53
|
|
54
|
|
- params['url'] = url.format(query=q)
|
55
|
|
- params['ammount'] = ammount
|
|
54
|
+ params['url'] = url.format(from_currency, to_currency)
|
|
55
|
+ params['amount'] = amount
|
56
|
56
|
params['from'] = from_currency
|
57
|
57
|
params['to'] = to_currency
|
58
|
58
|
params['from_name'] = iso4217_to_name(from_currency, 'en')
|
|
@@ -63,30 +63,27 @@ 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
|
71
|
74
|
|
72
|
75
|
answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
|
73
|
|
- resp.search_params['ammount'],
|
|
76
|
+ resp.search_params['amount'],
|
74
|
77
|
resp.search_params['from'],
|
75
|
|
- resp.search_params['ammount'] * conversion_rate,
|
|
78
|
+ resp.search_params['amount'] * conversion_rate,
|
76
|
79
|
resp.search_params['to'],
|
77
|
80
|
conversion_rate,
|
78
|
81
|
resp.search_params['from_name'],
|
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
|
|