diff --git a/modules/oney/browser.py b/modules/oney/browser.py index 6de85000c4ae860256f834aa1e98e1336e44c66b..3245cae8e018c01817f6340ca8e69077e9a068a0 100644 --- a/modules/oney/browser.py +++ b/modules/oney/browser.py @@ -25,7 +25,7 @@ from .pages import ( LoginPage, ClientPage, OperationsPage, ChoicePage, - CreditHome, CreditAccountPage, CreditHistory, + CreditHome, CreditAccountPage, CreditHistory, LastHistoryPage, ) __all__ = ['OneyBrowser'] @@ -46,6 +46,7 @@ class OneyBrowser(LoginBrowser): credit_home = URL(r'/site/s/detailcompte/detailcompte.html', CreditHome) credit_info = URL(r'/site/s/detailcompte/ongletdetailcompte.html', CreditAccountPage) credit_hist = URL(r'/site/s/detailcompte/exportoperations.html', CreditHistory) + last_hist = URL(r'/site/s/detailcompte/ongletdernieresoperations.html', LastHistoryPage) has_oney = False has_other = False @@ -67,9 +68,15 @@ def do_login(self): else: raise BrowserIncorrectPassword() + @need_login def go_site(self, site): if site == 'oney': - if self.credit_home.is_here() or self.credit_info.is_here() or self.credit_hist.is_here(): + if ( + self.credit_home.is_here() or self.credit_info.is_here() + or self.credit_hist.is_here() + or self.last_hist.is_here() + ): + self.choice.go() assert self.choice.is_here() if self.choice.is_here(): @@ -126,12 +133,12 @@ def iter_history(self, account): yield tr elif account._site == 'other': - self.credit_hist.go(params=self._build_hist_form()) - - d = date.today().replace(day=1) # TODO is it the right date? - for tr in self.page.iter_history(): - if new_date(tr.date) < d: - yield tr + if self.last_hist.go().has_transactions(): + self.credit_hist.go(params=self._build_hist_form()) + d = date.today().replace(day=1) # TODO is it the right date? + for tr in self.page.iter_history(): + if new_date(tr.date) < d: + yield tr @need_login def iter_coming(self, account): @@ -146,9 +153,9 @@ def iter_coming(self, account): yield tr elif account._site == 'other': - self.credit_hist.go(params=self._build_hist_form()) - d = date.today().replace(day=1) # TODO is it the right date? - for tr in self.page.iter_history(): - if new_date(tr.date) >= d: - yield tr - + if self.last_hist.go().has_transactions(): + self.credit_hist.go(params=self._build_hist_form()) + d = date.today().replace(day=1) # TODO is it the right date? + for tr in self.page.iter_history(): + if new_date(tr.date) >= d: + yield tr diff --git a/modules/oney/pages.py b/modules/oney/pages.py index da8ad0cef1c9ac422c01c9f56ed8cc54a3655fec..ff1db33a00c2ff8af9ca64a2470f6b4392cb944a 100644 --- a/modules/oney/pages.py +++ b/modules/oney/pages.py @@ -29,7 +29,7 @@ from weboob.tools.capabilities.bank.transactions import FrenchTransaction, sorted_transactions from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError from weboob.tools.date import parse_french_date -from weboob.browser.pages import HTMLPage, LoggedPage, pagination, XLSPage +from weboob.browser.pages import HTMLPage, LoggedPage, pagination, XLSPage, PartialHTMLPage from weboob.browser.elements import ListElement, ItemElement, method from weboob.browser.filters.standard import Env, CleanDecimal, CleanText, Field, Format, Currency from weboob.browser.filters.html import Attr @@ -246,3 +246,8 @@ def iter_history(self): tr.amount = Decimal(str(amount)) tr.date = parse_french_date(line[0]) yield tr + + +class LastHistoryPage(LoggedPage, PartialHTMLPage): + def has_transactions(self): + return not CleanText('//h2[contains(text(), "Vous n\'avez pas effectué d\'opération depuis votre dernier relevé de compte.")]')(self.doc)