From 2cf7acdf3293dd5b0f76597cd751c59899523e3f Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Tue, 28 Oct 2014 15:37:49 +0100 Subject: [PATCH] fix parsing of market accounts and factorization of the Transaction class --- modules/cmso/mobile/pages.py | 23 ++---------------- modules/cmso/transaction.py | 46 ++++++++++++++++++++++++++++++++++++ modules/cmso/web/browser.py | 3 +++ modules/cmso/web/pages.py | 14 ++++++----- 4 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 modules/cmso/transaction.py diff --git a/modules/cmso/mobile/pages.py b/modules/cmso/mobile/pages.py index ce501380..7c816e82 100644 --- a/modules/cmso/mobile/pages.py +++ b/modules/cmso/mobile/pages.py @@ -24,7 +24,8 @@ import re from weboob.deprecated.browser import Page from weboob.capabilities.bank import Account -from weboob.tools.capabilities.bank.transactions import FrenchTransaction + +from ..transaction import Transaction class LoginPage(Page): @@ -50,26 +51,6 @@ class AccountsPage(Page): yield account -class Transaction(FrenchTransaction): - PATTERNS = [(re.compile('^RET DAB (?P
\d{2})/?(?P\d{2})(/?(?P\d{2}))? (?P.*)'), - FrenchTransaction.TYPE_WITHDRAWAL), - (re.compile('CARTE (?P
\d{2})/(?P\d{2}) (?P.*)'), - FrenchTransaction.TYPE_CARD), - (re.compile('^(?PVIR(EMEN)?T? (SEPA)?(RECU|FAVEUR)?)( /FRM)?(?P.*)'), - FrenchTransaction.TYPE_TRANSFER), - (re.compile('^PRLV (?P.*)( \d+)?$'), FrenchTransaction.TYPE_ORDER), - (re.compile('^(CHQ|CHEQUE) .*$'), FrenchTransaction.TYPE_CHECK), - (re.compile('^(AGIOS /|FRAIS) (?P.*)'), FrenchTransaction.TYPE_BANK), - (re.compile('^(CONVENTION \d+ |F )?COTIS(ATION)? (?P.*)'), - FrenchTransaction.TYPE_BANK), - (re.compile('^REMISE (?P.*)'), FrenchTransaction.TYPE_DEPOSIT), - (re.compile('^(?P.*)( \d+)? QUITTANCE .*'), - FrenchTransaction.TYPE_ORDER), - (re.compile('^.* LE (?P
\d{2})/(?P\d{2})/(?P\d{2})$'), - FrenchTransaction.TYPE_UNKNOWN), - ] - - class TransactionsPage(Page): months = [u'janvier', u'février', u'mars', u'avril', u'mai', u'juin', u'juillet', u'août', u'septembre', u'octobre', u'novembre', u'décembre'] diff --git a/modules/cmso/transaction.py b/modules/cmso/transaction.py new file mode 100644 index 00000000..05381d50 --- /dev/null +++ b/modules/cmso/transaction.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2012 Romain Bignon +# +# 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 . + + +import re + +from weboob.tools.capabilities.bank.transactions import FrenchTransaction + + +class Transaction(FrenchTransaction): + PATTERNS = [(re.compile('^RET DAB (?P
\d{2})/?(?P\d{2})(/?(?P\d{2}))? (?P.*)'), + FrenchTransaction.TYPE_WITHDRAWAL), + (re.compile('CARTE (?P
\d{2})/(?P\d{2}) (?P.*)'), + FrenchTransaction.TYPE_CARD), + (re.compile('^(?PVIR(EMEN)?T? (SEPA)?(RECU|FAVEUR)?)( /FRM)?(?P.*)'), + FrenchTransaction.TYPE_TRANSFER), + (re.compile('^PRLV (?P.*)( \d+)?$'), FrenchTransaction.TYPE_ORDER), + (re.compile('^(CHQ|CHEQUE) .*$'), FrenchTransaction.TYPE_CHECK), + (re.compile('^(AGIOS /|FRAIS) (?P.*)'), FrenchTransaction.TYPE_BANK), + (re.compile('^(CONVENTION \d+ |F )?COTIS(ATION)? (?P.*)'), + FrenchTransaction.TYPE_BANK), + (re.compile('^REMISE (?P.*)'), FrenchTransaction.TYPE_DEPOSIT), + (re.compile('^(?P.*)( \d+)? QUITTANCE .*'), + FrenchTransaction.TYPE_ORDER), + (re.compile('^.* LE (?P
\d{2})/(?P\d{2})/(?P\d{2})$'), + FrenchTransaction.TYPE_UNKNOWN), + ] + + + diff --git a/modules/cmso/web/browser.py b/modules/cmso/web/browser.py index 08573b85..c0e74eac 100644 --- a/modules/cmso/web/browser.py +++ b/modules/cmso/web/browser.py @@ -53,6 +53,9 @@ class CmsoProBrowser(LoginBrowser): @need_login def get_history(self, account): + if account._history_url.startswith('javascript:'): + raise NotImplementedError() + # Query history for 6 last months def format_date(d): return datetime.date.strftime(d, '%d/%m/%Y') diff --git a/modules/cmso/web/pages.py b/modules/cmso/web/pages.py index dd94e339..d1664b54 100644 --- a/modules/cmso/web/pages.py +++ b/modules/cmso/web/pages.py @@ -25,9 +25,10 @@ from weboob.browser.elements import ListElement, ItemElement, method from weboob.browser.filters.standard import CleanText, CleanDecimal, Regexp, DateGuesser from weboob.browser.filters.html import Link from weboob.capabilities.bank import Account -from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.date import LinearDateGuesser +from ..transaction import Transaction + __all__ = ['LoginPage'] @@ -52,13 +53,14 @@ class AccountsPage(LoggedPage, HTMLPage): klass = Account obj__history_url = Link('./td[1]/a') - obj_id = obj__history_url & Regexp(pattern="indCptSelectionne=(\d+)") obj_label = CleanText('./td[1]') - obj_balance = CleanDecimal('./td[2]') + obj_id = obj__history_url & Regexp(pattern="indCptSelectionne=(\d+)") | None + obj_balance = CleanDecimal('./td[2]', replace_dots=True) - -class Transaction(FrenchTransaction): - pass + def validate(self, obj): + if obj.id is None: + obj.id = obj.label.replace(' ', '') + return True class CmsoTransactionElement(ItemElement):