diff --git a/currency_rate_update_coingecko/models/res_currency_rate_provider_CoinGecko.py b/currency_rate_update_coingecko/models/res_currency_rate_provider_CoinGecko.py index e14ca04..edea87c 100644 --- a/currency_rate_update_coingecko/models/res_currency_rate_provider_CoinGecko.py +++ b/currency_rate_update_coingecko/models/res_currency_rate_provider_CoinGecko.py @@ -46,7 +46,7 @@ def _get_historical_rate_from_coingecko(self, date_from, date_to, base_currency) while current_date <= date_to: content[current_date] = {} for ( - currency + currency ) in self.currency_ids.res_currency_rate_provider_mapping_ids.filtered( lambda rpm: rpm.provider_service == self.service ): @@ -68,19 +68,20 @@ def _get_historical_rate_from_coingecko(self, date_from, date_to, base_currency) body=_( 'Currency Rate Provider "%(name)s" failed to obtain data(check the rate provider mapping on the currency) :\n%(error)s' ) - % { - "name": self.name, - "currency": currency.currency_id.name, - "error": str(e) if e else _("N/A"), - }, + % { + "name": self.name, + "currency": currency.currency_id.name, + "error": str(e) if e else _("N/A"), + }, ) continue - rate = ( - coin_data.get("market_data") - .get("current_price") - .get(base_currency.lower(), 0) - ) - if rate: - content[current_date].update({currency.currency_id.name: 1 / rate}) + if coin_data: + rate = ( + coin_data.get("market_data", {}) + .get("current_price", {}) + .get(base_currency.lower(), 0) + ) + if rate: + content[current_date].update({currency.currency_id.name: 1 / rate}) current_date += timedelta(days=1) return content