From 4e86d14e12292719cf9864eb9563e4d981f2828d Mon Sep 17 00:00:00 2001 From: Johann Broudin Date: Tue, 28 Feb 2012 22:28:26 +0100 Subject: [PATCH] Add type and label support to CMB backend Signed-off-by: Johann Broudin Signed-off-by: Romain Bignon --- modules/cmb/backend.py | 48 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/modules/cmb/backend.py b/modules/cmb/backend.py index c95db6d7..c1c84be5 100644 --- a/modules/cmb/backend.py +++ b/modules/cmb/backend.py @@ -25,7 +25,7 @@ from weboob.tools.value import ValueBackendPassword from weboob.capabilities.base import NotAvailable from weboob.tools.browser import BrowserIncorrectPassword, BrokenPageError -from re import match +from re import match, compile, sub from httplib import HTTPSConnection from urllib import urlencode @@ -45,6 +45,45 @@ class CmbBackend(BaseBackend, ICapBank): CONFIG = BackendConfig( ValueBackendPassword('login', label='Account ID', masked=False), ValueBackendPassword('password', label='Password', masked=True)) + LABEL_PATTERNS = [ + ( # card + compile('^CARTE (?P.*)'), + Transaction.TYPE_CARD, + '%(text)s' + ), + ( # order + compile('^PRLV (?P.*)'), + Transaction.TYPE_ORDER, + '%(text)s' + ), + ( # withdrawal + compile('^RET DAB (?P.*)'), + Transaction.TYPE_WITHDRAWAL, + '%(text)s' + ), + ( # loan payment + compile('^ECH (?P.*)'), + Transaction.TYPE_LOAN_PAYMENT, + '%(text)s' + ), + ( # transfer + compile('^VIR (?P.*)'), + Transaction.TYPE_TRANSFER, + '%(text)s' + ), + ( # payback + compile('^ANN (?P.*)'), + Transaction.TYPE_PAYBACK, + '%(text)s' + ), + ( # bank + compile('^F (?P.*)'), + Transaction.TYPE_BANK, + '%(text)s' + ) + ] + + cookie = None headers = { 'User-Agent': @@ -211,12 +250,17 @@ class CmbBackend(BaseBackend, ICapBank): div = td[2].xpath('div') label = div[0].xpath('a')[0].text.replace('\n','') operation.raw = unicode(' '.join(label.split())) + for pattern, _type, _label in self.LABEL_PATTERNS: + mm = pattern.match(operation.raw) + if mm: + operation.type = _type + operation.label = sub('[ ]+', ' ', _label % mm.groupdict()).strip() + break amount = td[3].text if amount.count(',') != 1: amount = td[4].text amount = amount.replace(',','.').replace(u'\xa0','') - print repr(amount) operation.amount = float(amount) else: amount = amount.replace(',','.').replace(u'\xa0','')