From 981edd413acfdd4786faf5439d2a05d6d7e4649e Mon Sep 17 00:00:00 2001 From: Glandos Date: Thu, 7 May 2020 22:56:17 +0200 Subject: Improve currencies (#604) - Rename "No Currency" to ISO4217 "XXX" - Use Babel to render currency symbols and names in currency lists - Improve i18n in bill lists Fix #601 Fix #600 --- ihatemoney/currency_convertor.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ihatemoney/currency_convertor.py') diff --git a/ihatemoney/currency_convertor.py b/ihatemoney/currency_convertor.py index 75fa834..10026ee 100644 --- a/ihatemoney/currency_convertor.py +++ b/ihatemoney/currency_convertor.py @@ -13,7 +13,7 @@ class Singleton(type): class CurrencyConverter(object, metaclass=Singleton): # Get exchange rates - default = "No Currency" + no_currency = "XXX" api_url = "https://api.exchangeratesapi.io/latest?base=USD" def __init__(self): @@ -22,19 +22,23 @@ class CurrencyConverter(object, metaclass=Singleton): @cached(cache=TTLCache(maxsize=1, ttl=86400)) def get_rates(self): rates = requests.get(self.api_url).json()["rates"] - rates[self.default] = 1.0 + rates[self.no_currency] = 1.0 return rates - def get_currencies(self): - rates = [rate for rate in self.get_rates()] - rates.sort(key=lambda rate: "" if rate == self.default else rate) + def get_currencies(self, with_no_currency=True): + rates = [ + rate + for rate in self.get_rates() + if with_no_currency or rate != self.no_currency + ] + rates.sort(key=lambda rate: "" if rate == self.no_currency else rate) return rates def exchange_currency(self, amount, source_currency, dest_currency): if ( source_currency == dest_currency - or source_currency == self.default - or dest_currency == self.default + or source_currency == self.no_currency + or dest_currency == self.no_currency ): return amount -- cgit v1.1