aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/currency_convertor.py
diff options
context:
space:
mode:
Diffstat (limited to 'ihatemoney/currency_convertor.py')
-rw-r--r--ihatemoney/currency_convertor.py18
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