From a8e7e76cca9c242b35c2195eca64d43c5dd03358 Mon Sep 17 00:00:00 2001 From: Shane Padellaro Date: Thu, 9 Feb 2023 19:48:52 +0000 Subject: [PATCH 1/2] Changed forex provider and added a check to fix unit test --- forex_python/converter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index 4655b7b..f210697 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -25,7 +25,7 @@ def __init__(self, force_decimal=False): self._force_decimal = force_decimal def _source_url(self): - return "https://theforexapi.com/api/" + return "https://api.exchangerate.host/" def _get_date_string(self, date_obj): if date_obj is None: @@ -33,13 +33,15 @@ def _get_date_string(self, date_obj): date_str = date_obj.strftime('%Y-%m-%d') return date_str - def _decode_rates(self, response, use_decimal=False, date_str=None): + def _decode_rates(self, response, use_decimal=False, date_str=None,base_cur=None): if self._force_decimal or use_decimal: decoded_data = json.loads(response.text, use_decimal=True) else: decoded_data = response.json() # if (date_str and date_str != 'latest' and date_str != decoded_data.get('date')): # raise RatesNotAvailableError("Currency Rates Source Not Ready") + if base_cur != None and base_cur != decoded_data['base']: + raise RatesNotAvailableError("Currency Rates Source Not Ready") return decoded_data.get('rates', {}) def _get_decoded_rate( @@ -57,7 +59,7 @@ def get_rates(self, base_cur, date_obj=None): source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: - rates = self._decode_rates(response, date_str=date_str) + rates = self._decode_rates(response,date_str=date_str,base_cur=base_cur) return rates raise RatesNotAvailableError("Currency Rates Source Not Ready") From 73c330bb30f7e8ab5b4406445b40193958f2e37e Mon Sep 17 00:00:00 2001 From: Shane Padellaro Date: Mon, 13 Feb 2023 07:40:36 +0000 Subject: [PATCH 2/2] fixed spacing --- forex_python/converter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index f210697..7bac340 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -33,7 +33,7 @@ def _get_date_string(self, date_obj): date_str = date_obj.strftime('%Y-%m-%d') return date_str - def _decode_rates(self, response, use_decimal=False, date_str=None,base_cur=None): + def _decode_rates(self, response, use_decimal=False, date_str=None, base_cur=None): if self._force_decimal or use_decimal: decoded_data = json.loads(response.text, use_decimal=True) else: @@ -59,7 +59,7 @@ def get_rates(self, base_cur, date_obj=None): source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: - rates = self._decode_rates(response,date_str=date_str,base_cur=base_cur) + rates = self._decode_rates(response,date_str=date_str, base_cur=base_cur) return rates raise RatesNotAvailableError("Currency Rates Source Not Ready")