mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
data: currencies: use SQLite instead of JSON
This commit is contained in:
parent
83d4a2ebb0
commit
71f1789be0
7 changed files with 10155 additions and 15018 deletions
|
|
@ -3,33 +3,14 @@
|
|||
|
||||
"""
|
||||
|
||||
import unicodedata
|
||||
import re
|
||||
|
||||
from searx.data import CURRENCIES
|
||||
from searx.data import fetch_iso4217_from_user, fetch_name_from_iso4217
|
||||
from .online import OnlineProcessor
|
||||
|
||||
parser_re = re.compile('.*?(\\d+(?:\\.\\d+)?) ([^.0-9]+) (?:in|to) ([^.0-9]+)', re.I)
|
||||
|
||||
|
||||
def normalize_name(name):
|
||||
name = name.lower().replace('-', ' ').rstrip('s')
|
||||
name = re.sub(' +', ' ', name)
|
||||
return unicodedata.normalize('NFKD', name).lower()
|
||||
|
||||
|
||||
def name_to_iso4217(name):
|
||||
name = normalize_name(name)
|
||||
currency = CURRENCIES['names'].get(name, [name])
|
||||
if isinstance(currency, str):
|
||||
return currency
|
||||
return currency[0]
|
||||
|
||||
|
||||
def iso4217_to_name(iso4217, language):
|
||||
return CURRENCIES['iso4217'].get(iso4217, {}).get(language, iso4217)
|
||||
|
||||
|
||||
class OnlineCurrencyProcessor(OnlineProcessor):
|
||||
"""Processor class used by ``online_currency`` engines."""
|
||||
|
||||
|
|
@ -52,14 +33,17 @@ class OnlineCurrencyProcessor(OnlineProcessor):
|
|||
amount = float(amount_str)
|
||||
except ValueError:
|
||||
return None
|
||||
from_currency = name_to_iso4217(from_currency.strip())
|
||||
to_currency = name_to_iso4217(to_currency.strip())
|
||||
from_currency = fetch_iso4217_from_user(from_currency.strip())
|
||||
to_currency = fetch_iso4217_from_user(to_currency.strip())
|
||||
|
||||
if from_currency is None or to_currency is None:
|
||||
return None
|
||||
|
||||
params['amount'] = amount
|
||||
params['from'] = from_currency
|
||||
params['to'] = to_currency
|
||||
params['from_name'] = iso4217_to_name(from_currency, 'en')
|
||||
params['to_name'] = iso4217_to_name(to_currency, 'en')
|
||||
params['from_name'] = fetch_name_from_iso4217(from_currency, 'en')
|
||||
params['to_name'] = fetch_name_from_iso4217(to_currency, 'en')
|
||||
return params
|
||||
|
||||
def get_default_tests(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue