sgpe: Account history

This commit is contained in:
Laurent Bachelier 2013-07-22 16:48:33 +02:00
commit 888230f7e2
2 changed files with 46 additions and 2 deletions

View file

@ -21,7 +21,7 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from weboob.tools.ordereddict import OrderedDict from weboob.tools.ordereddict import OrderedDict
from .pages import LoginPage, AccountsPage from .pages import LoginPage, AccountsPage, HistoryPage
__all__ = ['SGProfessionalBrowser', 'SGEnterpriseBrowser'] __all__ = ['SGProfessionalBrowser', 'SGEnterpriseBrowser']
@ -34,6 +34,7 @@ class SGPEBrowser(BaseBrowser):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.PAGES = OrderedDict(( self.PAGES = OrderedDict((
('%s://%s/Pgn/.+PageID=SoldeV3&.+' % (self.PROTOCOL, self.DOMAIN), AccountsPage), ('%s://%s/Pgn/.+PageID=SoldeV3&.+' % (self.PROTOCOL, self.DOMAIN), AccountsPage),
('%s://%s/Pgn/.+PageID=ReleveCompteV3&.+' % (self.PROTOCOL, self.DOMAIN), HistoryPage),
('%s://%s/' % (self.PROTOCOL, self.DOMAIN), LoginPage), ('%s://%s/' % (self.PROTOCOL, self.DOMAIN), LoginPage),
)) ))
BaseBrowser.__init__(self, *args, **kwargs) BaseBrowser.__init__(self, *args, **kwargs)
@ -67,12 +68,26 @@ class SGPEBrowser(BaseBrowser):
def accounts(self): def accounts(self):
self.location('/Pgn/NavigationServlet?PageID=SoldeV3&MenuID=%s&Classeur=1&NumeroPage=1' % self.MENUID) self.location('/Pgn/NavigationServlet?PageID=SoldeV3&MenuID=%s&Classeur=1&NumeroPage=1' % self.MENUID)
def history(self, _id):
self.location('/Pgn/NavigationServlet?PageID=ReleveCompteV3&MenuID=%s&Classeur=1&Rib=%s&NumeroPage=1' % (self.MENUID, _id))
def get_accounts_list(self): def get_accounts_list(self):
if not self.is_on_page(AccountsPage): if not self.is_on_page(AccountsPage):
self.accounts() self.accounts()
assert self.is_on_page(AccountsPage) assert self.is_on_page(AccountsPage)
return self.page.get_list() return self.page.get_list()
def get_account(self, _id):
for a in self.get_accounts_list():
if a.id == _id:
yield a
def iter_history(self, account):
self.history(account.id)
assert self.is_on_page(HistoryPage)
for transaction in self.page.iter_transactions(account):
yield transaction
class SGProfessionalBrowser(SGPEBrowser): class SGProfessionalBrowser(SGPEBrowser):
DOMAIN = 'professionnels.secure.societegenerale.fr' DOMAIN = 'professionnels.secure.societegenerale.fr'

View file

@ -20,6 +20,7 @@
from logging import error from logging import error
import re import re
from decimal import Decimal from decimal import Decimal
from datetime import datetime
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.tools.json import json from weboob.tools.json import json
@ -35,6 +36,10 @@ from ..captcha import Captcha, TileError
__all__ = ['LoginPage', 'AccountsPage'] __all__ = ['LoginPage', 'AccountsPage']
class Transaction(FrenchTransaction):
_coming = False
class SGPEPage(BasePage): class SGPEPage(BasePage):
def get_error(self): def get_error(self):
err = self.document.getroot().cssselect('div.ngo_mire_reco_message') \ err = self.document.getroot().cssselect('div.ngo_mire_reco_message') \
@ -97,6 +102,30 @@ class AccountsPage(SGPEPage):
account.label = to_unicode(tdname) account.label = to_unicode(tdname)
account.id = to_unicode(tdid.replace(u'\xa0', '').replace(' ', '')) account.id = to_unicode(tdid.replace(u'\xa0', '').replace(' ', ''))
account._agency = to_unicode(tdagency) account._agency = to_unicode(tdagency)
account.balance = Decimal(FrenchTransaction.clean_amount(tdbalance)) account.balance = Decimal(Transaction.clean_amount(tdbalance))
account.currency = account.get_currency(tdbalance) account.currency = account.get_currency(tdbalance)
yield account yield account
class HistoryPage(SGPEPage):
def iter_transactions(self, account):
table = self.parser.select(self.document.getroot(), '#tab-corps', 1)
for i, tr in enumerate(self.parser.select(table, 'tr', 'many')):
tddate, tdlabel, tddebit, tdcredit, tdval, tdbal = [td.text_content().strip()
for td
in self.parser.select(tr, 'td', 4)]
tdamount = tddebit or tdcredit
# not sure it has empty rows like AccountsPage, but check anyway
if all((tddate, tdlabel, tdamount)):
t = Transaction(i)
t.set_amount(tdamount)
date = datetime.strptime(tddate, '%d/%m/%Y')
val = datetime.strptime(tdval, '%d/%m/%Y')
# so that first line is separated by parse()
# also clean up tabs, spaces, etc.
l1, _, l2 = tdlabel.partition('\n')
l1 = ' '.join(l1.split())
l2 = ' '.join(l2.split())
t.parse(date, l1 + ' ' + l2)
t._val = val # FIXME is it rdate? date?
yield t