summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorasciimoo <asciimoo@gmail.com>2013-12-01 16:41:24 +0100
committerasciimoo <asciimoo@gmail.com>2013-12-01 16:41:24 +0100
commita35128f5e0af70d2a858f736e020ce451f652565 (patch)
treef362b3468797c52213fb74c2ac1f1adde0b7f3ff /searx/engines
parentcfb06048acee3573cb92bf44d2e70234e31d6a76 (diff)
downloadsearxng-a35128f5e0af70d2a858f736e020ce451f652565.tar.gz
searxng-a35128f5e0af70d2a858f736e020ce451f652565.zip
[enh] smarter currency query parse
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/currency_convert.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py
index c6a4f29ca..b8ba7707f 100644
--- a/searx/engines/currency_convert.py
+++ b/searx/engines/currency_convert.py
@@ -1,21 +1,25 @@
from datetime import datetime
+import re
categories = []
url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s={query}=X'
weight = 100
+parser_re = re.compile(r'^\W*(\d+(?:\.\d+)?)\W*([a-z]{3})\W*(?:in)?\W*([a-z]{3})\W*$')
+
def request(query, params):
+ m = parser_re.match(query)
+ if not m:
+ # wrong query
+ return params
try:
- # eg.: "X EUR in USD"
- ammount, from_currency, _, to_currency = query.split()
+ ammount, from_currency, to_currency = m.groups()
ammount = float(ammount)
except:
# wrong params
return params
q = (from_currency+to_currency).upper()
- if not q.isalpha():
- return params
params['url'] = url.format(query=q)
params['ammount'] = ammount