diff options
| author | Glandos <bugs-github@antipoul.fr> | 2020-05-07 22:56:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-07 22:56:17 +0200 |
| commit | 981edd413acfdd4786faf5439d2a05d6d7e4649e (patch) | |
| tree | 3c1598baf52dd447fd806a5038e8b8f0c0e83fbc /ihatemoney/currency_convertor.py | |
| parent | 76911983af9e04e379853ab3c66804e73f5f16a0 (diff) | |
| download | ihatemoney-mirror-981edd413acfdd4786faf5439d2a05d6d7e4649e.zip ihatemoney-mirror-981edd413acfdd4786faf5439d2a05d6d7e4649e.tar.gz ihatemoney-mirror-981edd413acfdd4786faf5439d2a05d6d7e4649e.tar.bz2 | |
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
Diffstat (limited to 'ihatemoney/currency_convertor.py')
| -rw-r--r-- | ihatemoney/currency_convertor.py | 18 |
1 files changed, 11 insertions, 7 deletions
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 |
