def get_card_list(self): card_list = [] card_elements = self.doc.xpath( '//div[has-class("ccinc_cards")]/div[has-class("accordion")]') for card in card_elements: card_properties = {} # Regexp parse the text to extract the card number that may be in different formats card_properties['number'] = Regexp(CleanText('.'), '(\d+[\s|*]+\d+)', default=NotAvailable)(card) debit_info = (CleanText('.//div[@class="debit-info"]', default='')(card)) is_deferred = u'Débit différé' in debit_info is_immediate = u'Débit immédiat' in debit_info if is_immediate: card_properties['kind'] = self.browser.IMMEDIATE_CB elif is_deferred: card_properties['kind'] = self.browser.DEFERRED_CB else: raise DataError( "Cannot tell if the card {} is deferred or immediate". format(card_properties['number'])) card_list.append(card_properties) return card_list
def get_accounts_list(self): if self.accounts_list is None: self.accounts_list = [] # In case of password renewal, we need to go on ibans twice. self.ibans.go() ibans = self.page.get_ibans_dict() if self.ibans.is_here( ) else self.ibans.go().get_ibans_dict() # This page might be unavailable. try: ibans.update( self.transfer_init.go(data=JSON({'modeBeneficiaire': '0'}) ).get_ibans_dict('Crediteur')) except TransferError: pass accounts = list(self.accounts.go().iter_accounts(ibans)) self.market_syn.go(data=JSON({})) # do a post on the given URL market_accounts = self.page.get_list( ) # get the list of 'Comptes Titres' checked_accounts = set() for account in accounts: for market_acc in market_accounts: if all(( market_acc['securityAccountNumber'].endswith( account.number[-4:]), account.type in (Account.TYPE_MARKET, Account.TYPE_PEA), account.label == market_acc['securityAccountName'], not account.iban, )): if account.id in checked_accounts: # in this case, we have identified two accounts for the same CompteTitre raise DataError( 'we have two market accounts mapped to a same "CompteTitre" dictionary' ) checked_accounts.add(account.id) account.balance = market_acc.get( 'valorisation', account.balance) account.valuation_diff = market_acc['profitLoss'] break self.accounts_list.append(account) return iter(self.accounts_list)
def get_card_list(self): card_list = [] card_elements = self.doc.xpath('//div[has-class("ccinc_cards")]/div[has-class("accordion")]') for card in card_elements: card_properties = {} card_properties['number'] = Regexp(CleanText('.'), '([0-9]{4}\s\*{4}\s\*{4}\s[0-9]{4})')(card) debit_info = (CleanText('.//div[@class="debit-info"]', default='')(card)) is_deferred = debit_info.startswith(u'Débit différé') is_immediate = debit_info.startswith(u'Débit immédiat') if is_immediate: card_properties['kind'] = self.browser.IMMEDIATE_CB elif is_deferred: card_properties['kind'] = self.browser.DEFERRED_CB else: raise DataError("Cannot tell if this card is deferred or immediate") card_list.append(card_properties) return card_list
def iter_accounts(self): if self.accounts_list is None: self.accounts_list = [] # In case of password renewal, we need to go on ibans twice. self.ibans.go() ibans = self.page.get_ibans_dict() if self.ibans.is_here( ) else self.ibans.go().get_ibans_dict() # This page might be unavailable. try: ibans.update( self.transfer_init.go(data=JSON({'modeBeneficiaire': '0'}) ).get_ibans_dict('Crediteur')) except (TransferAssertionError, AttributeError): pass accounts = list(self.accounts.go().iter_accounts(ibans)) self.market_syn.go(data=JSON({})) # do a post on the given URL market_accounts = self.page.get_list( ) # get the list of 'Comptes Titres' checked_accounts = set() for account in accounts: for market_acc in market_accounts: if all(( market_acc['securityAccountNumber'].endswith( account.number[-4:]), account.type in (Account.TYPE_MARKET, Account.TYPE_PEA), account.label == market_acc['securityAccountName'], not account.iban, )): if account.id in checked_accounts: # in this case, we have identified two accounts for the same CompteTitre raise DataError( 'we have two market accounts mapped to a same "CompteTitre" dictionary' ) checked_accounts.add(account.id) account.balance = market_acc.get( 'valorisation', account.balance) account.valuation_diff = market_acc['profitLoss'] break self.accounts_list.append(account) # Fetching capitalisation contracts from the "Assurances Vie" space (some are not in the BNP API): params = self.natio_vie_pro.go().get_params() try: self.capitalisation_page.go(params=params) except ServerError: self.logger.warning("An Internal Server Error occurred") else: if self.capitalisation_page.is_here( ) and self.page.has_contracts(): for account in self.page.iter_capitalisation(): # Life Insurance accounts may appear BOTH in the API and the "Assurances Vie" domain, # It is better to keep the API version since it contains the unitvalue: if account.number not in [ a.number for a in self.accounts_list ]: self.logger.warning( "We found an account that only appears on the old BNP website." ) self.accounts_list.append(account) else: self.logger.warning( "This account was skipped because it already appears in the API." ) return iter(self.accounts_list)