[weboob] [PATCH 1/1] Add type and label support to CMB backend

Johann Broudin johann.broudin at 6-8.fr
Tue Feb 28 22:28:26 CET 2012


From: Johann Broudin <Johann.Broudin at 6-8.fr>


Signed-off-by: Johann Broudin <Johann.Broudin at 6-8.fr>
---
 modules/cmb/backend.py |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/modules/cmb/backend.py b/modules/cmb/backend.py
index c95db6d..c1c84be 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<text>.*)'),
+                Transaction.TYPE_CARD,
+                '%(text)s'
+            ),
+            (   # order
+                compile('^PRLV (?P<text>.*)'),
+                Transaction.TYPE_ORDER,
+                '%(text)s'
+            ),
+            (   # withdrawal
+                compile('^RET DAB (?P<text>.*)'),
+                Transaction.TYPE_WITHDRAWAL,
+                '%(text)s'
+            ),
+            (   # loan payment
+                compile('^ECH (?P<text>.*)'),
+                Transaction.TYPE_LOAN_PAYMENT,
+                '%(text)s'
+            ),
+            (   # transfer
+                compile('^VIR (?P<text>.*)'),
+                Transaction.TYPE_TRANSFER,
+                '%(text)s'
+            ),
+            (   # payback
+                compile('^ANN (?P<text>.*)'),
+                Transaction.TYPE_PAYBACK,
+                '%(text)s'
+            ),
+            (   # bank
+                compile('^F (?P<text>.*)'),
+                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','')
-- 
1.7.2.5




More information about the weboob mailing list