diff --git a/modules/cragr/api/browser.py b/modules/cragr/api/browser.py index 174b9620e74891293f1aac79fb28900ab2bfc6ba..af0148a3f94112809c0488e12a80d6b53000aef2 100644 --- a/modules/cragr/api/browser.py +++ b/modules/cragr/api/browser.py @@ -228,30 +228,32 @@ def iter_accounts(self): for contract in range(total_spaces): if not self.check_space_connection(contract): - self.logger.warning('Server returned error 500 twice when trying to access space %s, this space will be skipped' % contract) + self.logger.warning('Server returned error 500 twice when trying to access space %s, this space will be skipped', contract) continue - # The main account is not located at the same place in the JSON. - main_account = self.page.get_main_account() - if main_account.balance == NotAvailable: - self.check_space_connection(contract) + + # Some spaces have no main account + if self.page.has_main_account(): + # The main account is not located at the same place in the JSON. main_account = self.page.get_main_account() if main_account.balance == NotAvailable: - self.logger.warning('Could not fetch the balance for main account %s.' % main_account.id) - - # Get cards for the main account - if self.page.has_main_cards(): - for card in self.page.iter_main_cards(): - card.parent = main_account - card.currency = card.parent.currency - card.owner_type = card.parent.owner_type - card._category = card.parent._category - card._contract = contract - deferred_cards[card.id] = card - - main_account.owner_type = self.page.get_owner_type() - main_account._contract = contract - space_type = self.page.get_space_type() + self.check_space_connection(contract) + main_account = self.page.get_main_account() + if main_account.balance == NotAvailable: + self.logger.warning('Could not fetch the balance for main account %s.', main_account.id) + # Get cards for the main account + if self.page.has_main_cards(): + for card in self.page.iter_main_cards(): + card.parent = main_account + card.currency = card.parent.currency + card.owner_type = card.parent.owner_type + card._category = card.parent._category + card._contract = contract + deferred_cards[card.id] = card + main_account.owner_type = self.page.get_owner_type() + main_account._contract = contract + + space_type = self.page.get_space_type() accounts_list = list(self.page.iter_accounts()) for account in accounts_list: account._contract = contract diff --git a/modules/cragr/api/pages.py b/modules/cragr/api/pages.py index 97e8602e0e92b7a2171a67f47cd04cd6849e26f1..6a2f0f0bd2cd459afbc30d991100612aca808c6f 100644 --- a/modules/cragr/api/pages.py +++ b/modules/cragr/api/pages.py @@ -232,6 +232,9 @@ def get_connection_id(self): )(self.html_doc) return connection_id + def has_main_account(self): + return Dict('comptePrincipal', default=None)(self.doc) + @method class get_main_account(ItemElement): klass = Account