Skip to content

Commit

Permalink
hotfix: hardcode list of currencies to workaround failing API calls
Browse files Browse the repository at this point in the history
See #1232 for a discussion on currencies
  • Loading branch information
Baptiste Jonglez committed Oct 3, 2023
1 parent c5c8dba commit 21dab47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
29 changes: 23 additions & 6 deletions ihatemoney/currency_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,30 @@ def get_rates(self):
return rates

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
currencies = [
"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG",
"AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND",
"BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYN", "BZD", "CAD",
"CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUC",
"CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN",
"ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP",
"GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF",
"IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD",
"JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD",
"KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD",
"MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR",
"MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR",
"NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG",
"QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG",
"SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "STN",
"SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY",
"TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF",
"VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XDR",
"XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWL"
]
rates.sort(key=lambda rate: "" if rate == self.no_currency else rate)
return rates
if with_no_currency:
currencies.append(self.no_currency)
return currencies

def exchange_currency(self, amount, source_currency, dest_currency):
if (
Expand Down
6 changes: 3 additions & 3 deletions ihatemoney/tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ def test_only_one_instance(self):
assert one == two

def test_get_currencies(self):
assert set(self.converter.get_currencies()) == set(
["USD", "EUR", "CAD", "PLN", CurrencyConverter.no_currency]
)
currencies = self.converter.get_currencies()
for currency in ["USD", "EUR", "CAD", "PLN", CurrencyConverter.no_currency]:
assert currency in currencies

def test_exchange_currency(self):
result = self.converter.exchange_currency(100, "USD", "EUR")
Expand Down

0 comments on commit 21dab47

Please sign in to comment.