|
@@ -1,21 +1,25 @@
|
1
|
1
|
from datetime import datetime
|
|
2
|
+import re
|
2
|
3
|
|
3
|
4
|
categories = []
|
4
|
5
|
url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={query}=X'
|
5
|
6
|
weight = 100
|
6
|
7
|
|
|
8
|
+parser_re = re.compile(r'^\W*(\d+(?:\.\d+)?)\W*([a-z]{3})\W*(?:in)?\W*([a-z]{3})\W*$')
|
|
9
|
+
|
7
|
10
|
def request(query, params):
|
|
11
|
+ m = parser_re.match(query)
|
|
12
|
+ if not m:
|
|
13
|
+ # wrong query
|
|
14
|
+ return params
|
8
|
15
|
try:
|
9
|
|
- # eg.: "X EUR in USD"
|
10
|
|
- ammount, from_currency, _, to_currency = query.split()
|
|
16
|
+ ammount, from_currency, to_currency = m.groups()
|
11
|
17
|
ammount = float(ammount)
|
12
|
18
|
except:
|
13
|
19
|
# wrong params
|
14
|
20
|
return params
|
15
|
21
|
|
16
|
22
|
q = (from_currency+to_currency).upper()
|
17
|
|
- if not q.isalpha():
|
18
|
|
- return params
|
19
|
23
|
|
20
|
24
|
params['url'] = url.format(query=q)
|
21
|
25
|
params['ammount'] = ammount
|