## This file is part of weboob.## weboob is free software: you can redistribute it and/or modify# it under the terms of the GNU Affero General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## weboob is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU Affero General Public License for more details.## You should have received a copy of the GNU Affero General Public License# along with weboob. If not, see <http://www.gnu.org/licenses/>.

accounts=list(self.accounts.go().iter_accounts(ibans))self.market_syn.go(data=JSON({}))# do a post on the given URLmarket_accounts=self.page.get_list()# get the list of 'Comptes Titres'checked_accounts=set()

formarket_accinmarket_accounts:ifall((market_acc['securityAccountNumber'].endswith(account.number[-4:]),account.typein(Account.TYPE_MARKET,Account.TYPE_PEA),account.label==market_acc['securityAccountName'],notaccount.iban,)):ifaccount.idinchecked_accounts:# in this case, we have identified two accounts for the same CompteTitreraiseDataError('we have two market accounts mapped to a same "CompteTitre" dictionary')checked_accounts.add(account.id)

try:self.capitalisation_page.go(params=params)exceptServerError:self.logger.warning("An Internal Server Error occurred")else:ifself.capitalisation_page.is_here()andself.page.has_contracts():foraccountinself.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:ifaccount.numbernotin[a.numberforainself.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.")

# Life insurances and PERP may be scraped from the API or from the "Assurance Vie" space,# so we need to discriminate between both using account._details:ifaccount.typein(account.TYPE_LIFE_INSURANCE,account.TYPE_PERP,account.TYPE_CAPITALISATION):ifhasattr(account,'_details'):# Going to the "Assurances Vie" pagenatiovie_params=self.natio_vie_pro.go().get_params()self.capitalisation_page.go(params=natiovie_params)# Fetching the form to get the contract investments:capitalisation_params=self.page.get_params(account)self.capitalisation_page.go(params=capitalisation_params)returnself.page.iter_investments()else:# No capitalisation contract has yet been found in the API:assertaccount.type!=account.TYPE_CAPITALISATIONself.lifeinsurances.go(data=JSON({"ibanCrypte":account.id,}))returnself.page.iter_investments()

@need_logindefnew_recipient(self,recipient,**params):if'code'inparams:returnself.send_code(recipient,**params)# needed to get the phone number, enabling the possibility to send sms.self.recipients.go(data=JSON({'type':'TOUS'}))# post recipient data sending sms with same requestdata={}data['adresseBeneficiaire']=''data['iban']=recipient.ibandata['libelleBeneficiaire']=recipient.labeldata['notification']=Truedata['typeBeneficiaire']=''data['typeEnvoi']='SMS'recipient=self.add_recip.go(data=json.dumps(data),headers={'Content-Type':'application/json'}).get_recipient(recipient)

@need_logindefsend_code(self,recipient,**params):# depending on whether recipient is a weboob or a budgea backend object._id=recipient.webidifhasattr(recipient,'webid')elserecipient.iddata={}data['idBeneficiaire']=_iddata['typeActivation']=1data['codeActivation']=params['code']returnself.activate_recip.go(data=json.dumps(data),headers={'Content-Type':'application/json'}).get_recipient(recipient)@need_login