From 49da7aaf0785629c1c2f275ac7f99f15ebb2a424 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sun, 17 May 2015 16:28:19 +0200 Subject: [PATCH] fetch history of life insurances --- modules/fortuneo/browser.py | 12 ++-------- modules/fortuneo/pages/accounts_list.py | 31 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/modules/fortuneo/browser.py b/modules/fortuneo/browser.py index b108f185..a7569f86 100644 --- a/modules/fortuneo/browser.py +++ b/modules/fortuneo/browser.py @@ -19,9 +19,6 @@ # along with weboob. If not, see . -from datetime import date -from dateutil.relativedelta import relativedelta - from weboob.deprecated.browser import Browser, BrowserIncorrectPassword from .pages.login import LoginPage @@ -45,7 +42,7 @@ class Fortuneo(Browser): '.*/prive/mes-comptes/livret/consulter-situation/consulter-solde\.jsp.*' : AccountHistoryPage, '.*/prive/mes-comptes/compte-courant/consulter-situation/consulter-solde\.jsp.*' : AccountHistoryPage, - '.*/prive/mes-comptes/compte-titres-.*': InvestmentHistoryPage, + '.*/prive/mes-comptes/compte-titres-.*': PeaHistoryPage, '.*/prive/mes-comptes/assurance-vie.*': InvestmentHistoryPage, '.*/prive/mes-comptes/pea.*': PeaHistoryPage, '.*/prive/mes-comptes/compte-especes.*': InvestmentHistoryPage, @@ -93,12 +90,7 @@ class Fortuneo(Browser): def get_history(self, account): self.location(account._link_id) - if self.is_on_page(AccountHistoryPage): - self.select_form(name='ConsultationHistoriqueOperationsForm') - self.set_all_readonly(False) - self['dateRechercheDebut'] = (date.today() - relativedelta(years=1)).strftime('%d/%m/%Y') - self['nbrEltsParPage'] = '100' - self.submit() + self.page.select_period() return self.page.get_operations(account) diff --git a/modules/fortuneo/pages/accounts_list.py b/modules/fortuneo/pages/accounts_list.py index 16afb316..c1ba8627 100644 --- a/modules/fortuneo/pages/accounts_list.py +++ b/modules/fortuneo/pages/accounts_list.py @@ -22,6 +22,8 @@ from lxml.html import etree from decimal import Decimal import re from time import sleep +from datetime import date +from dateutil.relativedelta import relativedelta from weboob.capabilities.bank import Account, Investment from weboob.deprecated.browser import Page, BrowserIncorrectPassword @@ -88,6 +90,9 @@ class PeaHistoryPage(Page): return NotAvailable return Decimal(value) + def select_period(self): + pass + def get_operations(self, _id): return iter([]) @@ -124,14 +129,38 @@ class InvestmentHistoryPage(Page): return NotAvailable return Decimal(Transaction.clean_amount(value)) + def select_period(self): + self.browser.location(self.url.replace('portefeuille-assurance-vie.jsp', 'operations/assurance-vie-operations.jsp')) + + self.browser.select_form(name='OperationsForm') + self.browser.set_all_readonly(False) + self.browser['dateDebut'] = (date.today() - relativedelta(years=1)).strftime('%d/%m/%Y') + self.browser['nbrEltsParPage'] = '100' + self.browser.submit() + def get_operations(self, _id): - return iter([]) + for tr in self.document.xpath('//table[@id="tableau_histo_opes"]/tbody/tr'): + tds = tr.findall('td') + + t = Transaction() + t.parse(date=self.parser.tocleanstring(tds[1]), + raw=self.parser.tocleanstring(tds[2])) + t.set_amount(self.parser.tocleanstring(tds[-1])) + yield t class AccountHistoryPage(Page): def get_investments(self): return iter([]) + def select_period(self): + self.browser.select_form(name='ConsultationHistoriqueOperationsForm') + self.browser.set_all_readonly(False) + self.browser['dateRechercheDebut'] = (date.today() - relativedelta(years=1)).strftime('%d/%m/%Y') + self.browser['nbrEltsParPage'] = '100' + self.browser.submit() + + def get_operations(self, _id): """history, see http://docs.weboob.org/api/capabilities/bank.html?highlight=transaction#weboob.capabilities.bank.Transaction"""