diff --git a/modules/cragr/api/browser.py b/modules/cragr/api/browser.py index ff84f183afc03f43f6a668eec1bc214f88185938..04db2cca40be4544f3caa7fc5736d42a08cde569 100644 --- a/modules/cragr/api/browser.py +++ b/modules/cragr/api/browser.py @@ -35,7 +35,7 @@ from .pages import ( LoginPage, LoggedOutPage, KeypadPage, SecurityPage, ContractsPage, AccountsPage, AccountDetailsPage, TokenPage, IbanPage, HistoryPage, CardsPage, CardHistoryPage, NetfincaRedirectionPage, PredicaRedirectionPage, - PredicaInvestmentsPage, ProfilePage, + PredicaInvestmentsPage, ProfilePage, ProfileDetailsPage, ProProfileDetailsPage, ) from weboob.tools.capabilities.bank.investments import create_french_liquidity @@ -99,6 +99,10 @@ class CragrAPI(LoginBrowser): r'association/operations/synthese/jcr:content.npc.store.client.json', r'professionnel/operations/synthese/jcr:content.npc.store.client.json', ProfilePage) + profile_details = URL(r'particulier/operations/profil/infos-personnelles/gerer-coordonnees.html', ProfileDetailsPage) + + pro_profile_details = URL(r'association/operations/profil/infos-personnelles/controler-coordonnees.html', + r'professionnel/operations/profil/infos-personnelles/controler-coordonnees.html', ProProfileDetailsPage) def __init__(self, website, *args, **kwargs): super(CragrAPI, self).__init__(*args, **kwargs) @@ -446,12 +450,36 @@ def iter_investment(self, account): @need_login def iter_advisor(self): - raise BrowserUnavailable() + self.contracts_page.go(id_contract=0) + owner_type = self.page.get_owner_type() + self.profile_page.go() + if owner_type == 'PRIV': + advisor = self.page.get_advisor() + self.profile_details.go() + self.page.fill_advisor(obj=advisor) + return advisor + elif owner_type == 'ORGA': + advisor = self.page.get_advisor() + self.pro_profile_details.go() + self.page.fill_advisor(obj=advisor) + return advisor @need_login def get_profile(self): - #self.profile.go() - raise BrowserUnavailable() + # There is one profile per space, so we only fetch the first one + self.contracts_page.go(id_contract=0) + owner_type = self.page.get_owner_type() + self.profile_page.go() + if owner_type == 'PRIV': + profile = self.page.get_user_profile() + self.profile_details.go() + self.page.fill_profile(obj=profile) + return profile + elif owner_type == 'ORGA': + profile = self.page.get_company_profile() + self.pro_profile_details.go() + self.page.fill_profile(obj=profile) + return profile @need_login def iter_transfer_recipients(self, account): diff --git a/modules/cragr/api/pages.py b/modules/cragr/api/pages.py index 7f69c285490ee1cb970d279aac2055a0d436c9c2..20e2cdc54c7ac27148bbbd3cc690030c3fa7e638 100644 --- a/modules/cragr/api/pages.py +++ b/modules/cragr/api/pages.py @@ -29,10 +29,11 @@ from weboob.capabilities.bank import ( Account, AccountOwnerType, Transaction, Investment, ) - +from weboob.capabilities.profile import Person, Company +from weboob.capabilities.contact import Advisor from weboob.browser.elements import DictElement, ItemElement, method from weboob.browser.filters.standard import ( - CleanText, CleanDecimal, Currency as CleanCurrency, Format, Field, Map, Eval, Env, Regexp, + CleanText, CleanDecimal, Currency as CleanCurrency, Format, Field, Map, Eval, Env, Regexp, Date, ) from weboob.browser.filters.html import Attr from weboob.browser.filters.json import Dict @@ -402,4 +403,43 @@ def obj_code_type(self): class ProfilePage(LoggedPage, JsonPage): - pass \ No newline at end of file + @method + class get_user_profile(ItemElement): + klass = Person + + obj_name = CleanText(Dict('displayName', default=NotAvailable)) + obj_phone = CleanText(Dict('branchPhone', default=NotAvailable)) + obj_birth_date = Date(Dict('birthdate', default=NotAvailable)) + + @method + class get_company_profile(ItemElement): + klass = Company + + obj_name = CleanText(Dict('displayName', default=NotAvailable)) + obj_phone = CleanText(Dict('branchPhone', default=NotAvailable)) + obj_registration_date = Date(Dict('birthdate', default=NotAvailable)) + + @method + class get_advisor(ItemElement): + klass = Advisor + + def obj_name(self): + # If no advisor is displayed, we return the agency advisor. + if Dict('advisorGivenName')(self) and Dict('advisorFamilyName')(self): + return Format('%s %s', CleanText(Dict('advisorGivenName')), CleanText(Dict('advisorFamilyName')))(self) + return Format('%s %s', CleanText(Dict('branchManagerGivenName')), CleanText(Dict('branchManagerFamilyName')))(self) + + +class ProfileDetailsPage(LoggedPage, HTMLPage): + @method + class fill_profile(ItemElement): + obj_email = CleanText('//p[contains(@class, "Data mail")]', default=NotAvailable) + obj_address = CleanText('//p[strong[contains(text(), "Adresse")]]/text()[2]', default=NotAvailable) + + @method + class fill_advisor(ItemElement): + obj_phone = CleanText('//div[@id="blockConseiller"]//a[contains(@class, "advisorNumber")]', default=NotAvailable) + + +class ProProfileDetailsPage(ProfileDetailsPage): + pass