From efa39af9570140ce66f2421cbcb0c010d8c7054b Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sun, 28 Jul 2013 18:49:18 +0200 Subject: [PATCH] sort entries by value date (taken for Transaction.date) --- modules/banquepopulaire/browser.py | 6 ++++++ modules/banquepopulaire/pages.py | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/banquepopulaire/browser.py b/modules/banquepopulaire/browser.py index eeb2674b..864b6d25 100644 --- a/modules/banquepopulaire/browser.py +++ b/modules/banquepopulaire/browser.py @@ -38,6 +38,7 @@ class BanquePopulaire(BaseBrowser): 'https://[^/]+/cyber/internet/StartTask.do\?taskInfoOID=accueilSynthese.*': AccountsPage, 'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=SOLDE.*': TransactionsPage, 'https://[^/]+/cyber/internet/Page.do\?.*': TransactionsPage, + 'https://[^/]+/cyber/internet/Sort.do\?.*': TransactionsPage, 'https://[^/]+/s3f-web/indispo.*': UnavailablePage, 'https://[^/]+/portailinternet/_layouts/Ibp.Cyi.Layouts/RedirectSegment.aspx.*': RedirectPage, 'https://[^/]+/portailinternet/Catalogue/Segments/.*.aspx\?vary=(?P.*)': HomePage, @@ -103,6 +104,11 @@ class BanquePopulaire(BaseBrowser): account = self.get_account(account.id) self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(account._params)) + # Sort by values dates (see comment in TransactionsPage.get_history) + self.select_form(predicate=lambda form: form.attrs.get('id', '') == 'myForm') + self.form.action = self.absurl('/cyber/internet/Sort.do?property=tbl1&sortBlocId=blc2&columnName=dateValeur') + self.submit() + while True: assert self.is_on_page(TransactionsPage) diff --git a/modules/banquepopulaire/pages.py b/modules/banquepopulaire/pages.py index 7fcada0a..b938e363 100644 --- a/modules/banquepopulaire/pages.py +++ b/modules/banquepopulaire/pages.py @@ -283,6 +283,13 @@ class TransactionsPage(BasePage): return params + COL_COMPTA_DATE = 0 + COL_LABEL = 1 + COL_REF = 2 + COL_OP_DATE = 3 + COL_VALUE_DATE = 4 + COL_DEBIT = -2 + COL_CREDIT = -1 def get_history(self): for tr in self.document.xpath('//table[@id="tbl1"]/tbody/tr'): tds = tr.findall('td') @@ -292,10 +299,15 @@ class TransactionsPage(BasePage): t = Transaction(tr.attrib['id'].split('_', 1)[1]) - date = u''.join([txt.strip() for txt in tds[4].itertext()]) - raw = u' '.join([txt.strip() for txt in tds[1].itertext()]) - debit = u''.join([txt.strip() for txt in tds[-2].itertext()]) - credit = u''.join([txt.strip() for txt in tds[-1].itertext()]) + # XXX We currently take the *value* date, but it will probably + # necessary to use the *operation* one. + # Default sort on website is by compta date, so in browser.py we + # change the sort on value date. + date = self.parser.tocleanstring(tds[self.COL_VALUE_DATE]) + raw = self.parser.tocleanstring(tds[self.COL_LABEL]) + debit = self.parser.tocleanstring(tds[self.COL_DEBIT]) + credit = self.parser.tocleanstring(tds[self.COL_CREDIT]) + t.parse(date, re.sub(r'[ ]+', ' ', raw)) t.set_amount(credit, debit) yield t