From bb4e6f235732d61070ba6abad4de2806769ec9b8 Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Tue, 3 Oct 2023 13:08:53 +0200 Subject: [PATCH] hotfix: hardcode list of currencies to workaround failing API calls See https://github.com/spiral-project/ihatemoney/issues/1232 for a discussion on currencies --- ihatemoney/currency_convertor.py | 180 +++++++++++++++++++++++++++++-- ihatemoney/tests/main_test.py | 6 +- 2 files changed, 177 insertions(+), 9 deletions(-) diff --git a/ihatemoney/currency_convertor.py b/ihatemoney/currency_convertor.py index 1139a4455..ca0ff3669 100644 --- a/ihatemoney/currency_convertor.py +++ b/ihatemoney/currency_convertor.py @@ -36,13 +36,181 @@ 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 ( diff --git a/ihatemoney/tests/main_test.py b/ihatemoney/tests/main_test.py index 70c119088..be0868913 100644 --- a/ihatemoney/tests/main_test.py +++ b/ihatemoney/tests/main_test.py @@ -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")