From b673880f34d527fe2806d4e1128e40d422c886fd Mon Sep 17 00:00:00 2001 From: Edouard Lambert Date: Fri, 3 Feb 2017 17:52:44 +0100 Subject: [PATCH] adding CapProfile to cragr --- modules/cragr/module.py | 8 +++++++- modules/cragr/web/browser.py | 11 ++++++++++- modules/cragr/web/pages.py | 24 +++++++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/modules/cragr/module.py b/modules/cragr/module.py index 75bf8a98ba..4119cb9e90 100644 --- a/modules/cragr/module.py +++ b/modules/cragr/module.py @@ -22,6 +22,7 @@ from weboob.capabilities.bank import Account, AccountNotFound, CapBankTransfer from weboob.capabilities.contact import CapContact +from weboob.capabilities.profile import CapProfile from weboob.tools.backend import Module, BackendConfig from weboob.tools.value import ValueBackendPassword, Value @@ -31,7 +32,7 @@ __all__ = ['CragrModule'] -class CragrModule(Module, CapBankTransfer, CapContact): +class CragrModule(Module, CapBankTransfer, CapContact, CapProfile): NAME = 'cragr' MAINTAINER = u'Romain Bignon' EMAIL = 'romain@weboob.org' @@ -115,6 +116,11 @@ def iter_investment(self, account): def iter_contacts(self): return self.browser.iter_advisor() + def get_profile(self): + if not hasattr(self.browser, 'get_profile'): + raise NotImplementedError() + return self.browser.get_profile() + def iter_transfer_recipients(self, account): if not isinstance(account, Account): account = self.get_account(account) diff --git a/modules/cragr/web/browser.py b/modules/cragr/web/browser.py index 0a29aea3f1..f0d7cdcbe4 100644 --- a/modules/cragr/web/browser.py +++ b/modules/cragr/web/browser.py @@ -36,7 +36,7 @@ SavingsPage, TransactionsPage, AdvisorPage, UselessPage, CardsPage, LifeInsurancePage, MarketPage, LoansPage, PerimeterPage, ChgPerimeterPage, MarketHomePage, FirstVisitPage, BGPIPage, - TransferInit, TransferPage, + TransferInit, TransferPage, ProfilePage, ) @@ -81,6 +81,7 @@ class Cragr(LoginBrowser): advisor = URL(r'/stb/entreeBam\?.*act=Contact', r'https://.*/vitrine/tracking/t/', AdvisorPage) + profile = URL(r'/stb/entreeBam\?.*act=Coordonnees', ProfilePage) login_error = URL(r'/stb/.*/erreur/.*', LoginErrorPage) cards = URL(r'/stb/collecteNI\?.*fwkaction=Cartes.*', r'/stb/collecteNI\?.*sessionAPP=Cartes.*', @@ -207,6 +208,7 @@ def do_login(self): self.savings_url = re.sub('act=([^&=]+)', 'act=Synthepargnes', self.accounts_url, 1) self.loans_url = re.sub('act=([^&=]+)', 'act=Synthcredits', self.accounts_url, 1) self.advisor_url = re.sub('act=([^&=]+)', 'act=Contact', self.accounts_url, 1) + self.profile_url = re.sub('act=([^&=]+)', 'act=Coordonnees', self.accounts_url, 1) if self.page.check_perimeters() and not self.broken_perimeters: self.perimeter_url = re.sub('act=([^&=]+)', 'act=Perimetre', self.accounts_url, 1) @@ -415,6 +417,13 @@ def iter_advisor(self): for adv in self.page.iter_numbers(): yield adv + @need_login + def get_profile(self): + if not self.profile.is_here(): + self.location(self.profile_url.format(self.sag)) + + return self.page.get_profile() + @need_login def moveto_market_website(self, account, home=False): response = self.open(account._link % self.sag).text diff --git a/modules/cragr/web/pages.py b/modules/cragr/web/pages.py index 98e1bd4f15..3936c6b0b5 100644 --- a/modules/cragr/web/pages.py +++ b/modules/cragr/web/pages.py @@ -29,11 +29,12 @@ from weboob.capabilities.base import Currency from weboob.capabilities.bank import Account, Investment, Recipient, Transfer, TransferError from weboob.capabilities.contact import Advisor +from weboob.capabilities.profile import Profile from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction from weboob.tools.date import parse_french_date, LinearDateGuesser from weboob.browser.elements import ItemElement, method -from weboob.browser.filters.standard import Date, CleanText, CleanDecimal, Currency as CleanCurrency, Regexp +from weboob.browser.filters.standard import Date, CleanText, CleanDecimal, Currency as CleanCurrency, Regexp, Format class MyLoggedPage(object): @@ -788,6 +789,27 @@ def iter_numbers(self): yield adv +class ProfilePage(MyLoggedPage, BasePage): + @method + class get_profile(ItemElement): + klass = Profile + + obj_email = Regexp(CleanText('//font/b/script[contains(text(), "Mail")]', default=""), '\'([^\']+)', default=NotAvailable) + + def obj_address(self): + address = "" + for tr in self.page.doc.xpath('//tr[td[contains(text(), "Adresse")]]/following-sibling::tr[position() < 4]'): + address += " " + CleanText('./td[last()]')(tr).strip() + return ' '.join(address.split()) or NotAvailable + + def obj_name(self): + name = CleanText('//span[contains(text(), "Espace Titulaire")]', default=None)(self) + if name and not "particuliers" in name: + return ''.join(name.split(':')[1:]).strip() + pattern = u'//td[contains(text(), "%s")]/following-sibling::td[1]' + return Format('%s %s', CleanText(pattern % "Nom"), CleanText(pattern % "Prénom"))(self) + + class BGPIPage(MarketPage): COL_ID = 0 COL_QUANTITY = 1 -- GitLab