summaryrefslogtreecommitdiff
path: root/searx/engines/currency_convert.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2020-10-07 10:38:13 +0200
committerGitHub <noreply@github.com>2020-10-07 10:38:13 +0200
commit8b278cbfad3f39cc71cb41954d37b30c7d16d947 (patch)
tree1cf83faca105df629ea06a3492884001d6b4d84c /searx/engines/currency_convert.py
parente30dc2f0ba481e033f127e5619d90cdc05d6db25 (diff)
parenta9dc54bebc943000252975ef25ddcb51681fc284 (diff)
Merge pull request #2246 from dalf/mod-searx-data
[mod] Add searx.data module
Diffstat (limited to 'searx/engines/currency_convert.py')
-rw-r--r--searx/engines/currency_convert.py28
1 files changed, 7 insertions, 21 deletions
diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py
index c6067c4a8..4a82cfdca 100644
--- a/searx/engines/currency_convert.py
+++ b/searx/engines/currency_convert.py
@@ -1,11 +1,11 @@
import json
import re
-import os
import unicodedata
-from io import open
from datetime import datetime
+from searx.data import CURRENCIES
+
categories = []
url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
@@ -13,8 +13,6 @@ weight = 100
parser_re = re.compile('.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
-db = 1
-
def normalize_name(name):
name = name.lower().replace('-', ' ').rstrip('s')
@@ -23,17 +21,17 @@ def normalize_name(name):
def name_to_iso4217(name):
- global db
+ global CURRENCIES
name = normalize_name(name)
- currencies = db['names'].get(name, [name])
- return currencies[0]
+ currency = CURRENCIES['names'].get(name, [name])
+ return currency[0]
def iso4217_to_name(iso4217, language):
- global db
+ global CURRENCIES
- return db['iso4217'].get(iso4217, {}).get(language, iso4217)
+ return CURRENCIES['iso4217'].get(iso4217, {}).get(language, iso4217)
def request(query, params):
@@ -82,15 +80,3 @@ def response(resp):
results.append({'answer': answer, 'url': url})
return results
-
-
-def load():
- global db
-
- current_dir = os.path.dirname(os.path.realpath(__file__))
- json_data = open(current_dir + "/../data/currencies.json", 'r', encoding='utf-8').read()
-
- db = json.loads(json_data)
-
-
-load()