summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrinpatch <rinpatch@airmail.cc>2018-04-22 13:46:13 +0300
committerrinpatch <rinpatch@airmail.cc>2018-04-22 13:46:13 +0300
commita305dae9d88fe3c37ef18e4ce5cbe75f07c40a45 (patch)
tree0eda5d83c83edb95b7e3e0650c31441d0dd488b0
parent829d4793125b9214f9c80c807807343783b4715b (diff)
downloadsearxng-a305dae9d88fe3c37ef18e4ce5cbe75f07c40a45.tar.gz
searxng-a305dae9d88fe3c37ef18e4ce5cbe75f07c40a45.zip
switched currency convert to duckduckgo and added Bitcoin to currency list
-rw-r--r--searx/data/currencies.json16
-rw-r--r--searx/engines/currency_convert.py13
2 files changed, 19 insertions, 10 deletions
diff --git a/searx/data/currencies.json b/searx/data/currencies.json
index bfde5a74a..ad4e08fd4 100644
--- a/searx/data/currencies.json
+++ b/searx/data/currencies.json
@@ -6163,9 +6163,21 @@
],
"scellino keniota": [
"KES"
- ]
+ ],
+ "bitcoin": [
+ "XBT"
+ ]
},
"iso4217": {
+ "XBT":{
+ "fr": "Bitcoin",
+ "en": "Bitcoin",
+ "nl": "Bitcoin",
+ "de": "Bitcoin",
+ "it": "Bitcoin",
+ "hu": "Bitcoin",
+ "es": "Bitcoin"
+ },
"DZD": {
"fr": "Dinar alg\u00e9rien",
"en": "Algerian dinar",
@@ -7652,4 +7664,4 @@
"es": "Libra sudanesa"
}
}
-} \ No newline at end of file
+}
diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py
index 9c1c2f7b3..26e716b32 100644
--- a/searx/engines/currency_convert.py
+++ b/searx/engines/currency_convert.py
@@ -11,7 +11,7 @@ if sys.version_info[0] == 3:
unicode = str
categories = []
-url = 'https://finance.google.com/finance/converter?a=1&from={0}&to={1}'
+url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
weight = 100
parser_re = re.compile(b'.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
@@ -63,16 +63,13 @@ def request(query, params):
def response(resp):
+ """remove first and last lines to get only json"""
+ json_resp = resp.text[resp.text.find('\n')+1:resp.text.rfind('\n')-2]
results = []
- pat = '<span class=bld>(.+) {0}</span>'.format(
- resp.search_params['to'].upper())
-
try:
- conversion_rate = re.findall(pat, resp.text)[0]
- conversion_rate = float(conversion_rate)
+ conversion_rate = float(json.loads(json_resp)['conversion']['converted-amount'])
except:
return results
-
answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
resp.search_params['amount'],
resp.search_params['from'],
@@ -83,7 +80,7 @@ def response(resp):
resp.search_params['to_name'],
)
- url = 'https://finance.google.com/finance?q={0}{1}'.format(
+ url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'.format(
resp.search_params['from'].upper(), resp.search_params['to'])
results.append({'answer': answer, 'url': url})