[weboob] [PATCH 1/1] Add the history for Livret A account (ing)

Florent weboob at flo.fourcot.fr
Mon Jan 9 16:23:24 CET 2012


Signed-off-by: Florent <weboob at flo.fourcot.fr>
---
 weboob/backends/ing/browser.py               |   14 ++++++++--
 weboob/backends/ing/pages/__init__.py        |    4 +-
 weboob/backends/ing/pages/account_history.py |   35 +++++++++++++++++++++++--
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/weboob/backends/ing/browser.py b/weboob/backends/ing/browser.py
index f13c46f..95dfbcc 100644
--- a/weboob/backends/ing/browser.py
+++ b/weboob/backends/ing/browser.py
@@ -32,7 +32,8 @@ class Ing(BaseBrowser):
     PAGES = {'.*displayTRAccountSummary.*':   pages.AccountsList,
              '.*displayLogin.jsf':            pages.LoginPage,
              '.*displayLogin.jsf.*':          pages.LoginPage2,
-             '.*accountDetail.jsf.*':         pages.AccountHistory
+             '.*accountDetail.jsf.*':         pages.AccountHistoryCC,
+             '.*displayTRHistoriqueLA.*':     pages.AccountHistoryLA
             }
 
     def __init__(self, *args, **kwargs):
@@ -78,8 +79,15 @@ class Ing(BaseBrowser):
         return None
 
     def get_history(self, id):
-        # TODO: It works only with the Compte Courant, Livret A use an another page...
-        self.location('https://secure.ingdirect.fr/protected/pages/cc/accountDetail.jsf')
+        account = self.get_account(id)
+        # The first and the second letter of the label are the account type
+        if account.label[0:2] == "CC":
+          self.location('https://secure.ingdirect.fr/protected/pages/cc/accountDetail.jsf')
+        elif account.label[0:2] == "LA": 
+          # we want "displayTRHistoriqueLA" but this fucking page is not directly available... 
+          self.location('https://secure.ingdirect.fr/general?command=goToAccount&account=%d&zone=COMPTE' % int(id))
+        else: 
+          raise NotImplementedError()
         return self.page.get_operations()
 
     # TODO
diff --git a/weboob/backends/ing/pages/__init__.py b/weboob/backends/ing/pages/__init__.py
index 2b77ddc..1595c5e 100644
--- a/weboob/backends/ing/pages/__init__.py
+++ b/weboob/backends/ing/pages/__init__.py
@@ -19,10 +19,10 @@
 
 
 from .accounts_list import AccountsList
-from .account_history import AccountHistory
+from .account_history import AccountHistoryCC, AccountHistoryLA
 from .login import LoginPage, LoginPage2, ConfirmPage, MessagePage
 
 class AccountPrelevement(AccountsList): pass
 
-__all__ = ['AccountsList', 'AccountHistory', 'LoginPage', 'LoginPage2',
+__all__ = ['AccountsList', 'AccountHistoryCC', 'AccountHistoryLA', 'LoginPage', 'LoginPage2',
            'ConfirmPage', 'MessagePage', 'AccountPrelevement']
diff --git a/weboob/backends/ing/pages/account_history.py b/weboob/backends/ing/pages/account_history.py
index c4a9dea..64fd70a 100644
--- a/weboob/backends/ing/pages/account_history.py
+++ b/weboob/backends/ing/pages/account_history.py
@@ -22,12 +22,12 @@ from datetime import date
 
 from weboob.tools.browser import BasePage
 from weboob.capabilities.bank import Operation
+from weboob.capabilities.base import NotAvailable
 
+__all__ = ['AccountHistoryCC', 'AccountHistoryLA']
 
-__all__ = ['AccountHistory']
 
-
-class AccountHistory(BasePage):
+class AccountHistoryCC(BasePage):
 
     def on_loaded(self):
         self.operations = []
@@ -49,3 +49,32 @@ class AccountHistory(BasePage):
 
     def get_operations(self):
         return self.operations
+
+class AccountHistoryLA(BasePage): 
+    
+    def on_loaded(self):
+        self.operations = []
+        i = 1 
+        history = self.document.xpath('//tr[@align="center"]')
+        history.pop(0)
+        for tr in history:
+           id = i
+           texte = tr.text_content().strip().split('\n')
+           op = Operation(id)
+           # The size is not the same if there are two dates or only one
+           length = len(texte)
+           op.label = unicode(texte[length - 2].strip())
+           op.date = date(*reversed([int(x) for x in texte[0].split('/')]))
+           op.category = NotAvailable
+           
+           amount =  texte[length - 1].replace('\t','').strip().replace('.', '').replace(u'€', '').replace(',', '.').replace(u'\xa0', u'')
+           op.amount = float(amount)
+
+
+           self.operations.append(op)
+           i += 1
+           
+
+    def get_operations(self):
+        return self.operations
+
-- 
1.7.2.5



More information about the weboob mailing list