[weboob] [PATCH 3/3] LCL: implement account history

Pierre Mazière pierre.maziere at gmail.com
Sun Mar 6 23:47:54 CET 2011


Signed-off-by: Pierre Mazière <pierre.maziere at gmail.com>
---
 weboob/backends/lcl/backend.py |    6 ++++--
 weboob/backends/lcl/browser.py |    8 +++++++-
 weboob/backends/lcl/pages.py   |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/weboob/backends/lcl/backend.py b/weboob/backends/lcl/backend.py
index be339a0..416fe2a 100644
--- a/weboob/backends/lcl/backend.py
+++ b/weboob/backends/lcl/backend.py
@@ -58,5 +58,7 @@ class LCLBackend(BaseBackend, ICapBank):
         return iter([])
 
     def iter_history(self, account):
-        """ TODO Not supported yet """
-        return iter([])
+      with self.browser:
+        for history in self.browser.get_history(account):
+          yield history
+
diff --git a/weboob/backends/lcl/browser.py b/weboob/backends/lcl/browser.py
index b1b2252..bf2b147 100644
--- a/weboob/backends/lcl/browser.py
+++ b/weboob/backends/lcl/browser.py
@@ -18,7 +18,7 @@
 
 from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
 
-from .pages import LoginPage, LoginErrorPage, FramePage, AccountsPage
+from .pages import LoginPage, LoginErrorPage, FramePage, AccountsPage, AccountHistoryPage
 
 
 __all__ = ['LCLBrowser']
@@ -35,6 +35,7 @@ class LCLBrowser(BaseBrowser):
         'https://particuliers.secure.lcl.fr/everest/UWBI/UWBIAccueil\?DEST=IDENTIFICATION': LoginErrorPage,
         'https://particuliers.secure.lcl.fr/outil/UWSP/Synthese/accesSynthese': AccountsPage,
         'https://particuliers.secure.lcl.fr/outil/UWB2/Accueil\?DEST=INIT': FramePage,
+        'https://particuliers.secure.lcl.fr/outil/UWLM/ListeMouvementsPro/accesListeMouvementsPro.*':  AccountHistoryPage,
         }
 
     def __init__(self, agency, *args, **kwargs):
@@ -73,6 +74,11 @@ class LCLBrowser(BaseBrowser):
 
         return None
 
+    def get_history(self,account):
+      if not self.is_on_page(AccountHistoryPage) :
+        self.location('%s://%s%s' % (self.PROTOCOL, self.DOMAIN, account.link_id))
+      return self.page.get_operations()
+
     #def get_coming_operations(self, account):
     #    if not self.is_on_page(AccountComing) or self.page.account.id != account.id:
     #        self.location('/NS_AVEEC?ch4=%s' % account.link_id)
diff --git a/weboob/backends/lcl/pages.py b/weboob/backends/lcl/pages.py
index de3f9a5..b81b04c 100644
--- a/weboob/backends/lcl/pages.py
+++ b/weboob/backends/lcl/pages.py
@@ -16,6 +16,8 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
+from datetime import date
+from weboob.capabilities.bank import Operation
 from weboob.capabilities.bank import Account
 from weboob.tools.browser import BasePage
 
@@ -52,3 +54,37 @@ class AccountsPage(BasePage):
           l.append(account)
 
       return l
+
+class AccountHistoryPage(BasePage):
+  def on_loaded(self):
+    self.operations = []
+    done=False
+    for table in self.document.getiterator('table'):
+      title_tr=table.find('tr')
+      if title_tr is None:
+        continue
+      for text in title_tr.itertext():
+        prefix='Opérations effectuées'
+        if text.startswith(prefix.decode('utf-8')):
+          for tr in table.iter('tr'):
+            tr_class=tr.attrib.get('class')
+            if tr_class == 'tbl1' or tr_class=='tbl2':
+              tds=tr.findall('td')
+              d=date(*reversed([int(x) for x in tds[0].text.split('/')]))
+              label=u''+tds[1].find('a').text.strip()
+              if tds[3].text.strip() != u"":
+                amount = - float(tds[3].text.strip().replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ',''))
+              else:
+                amount= float(tds[4].text.strip().replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ',''))
+              operation=Operation(len(self.operations))
+              operation.date=d
+              operation.label=label
+              operation.amount=amount
+              self.operations.append(operation)
+          done=True
+          break
+      if done:
+        break
+
+  def get_operations(self):
+    return self.operations
-- 
1.7.2.3




More information about the weboob mailing list