bnporc[ent]: Get history
Only the last day for now
This commit is contained in:
parent
ab7c812056
commit
9760ca6e23
2 changed files with 52 additions and 5 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
|
|
||||||
from .pages import LoginPage, AccountsPage, UnknownPage
|
from .pages import LoginPage, AccountsPage, HistoryPage, UnknownPage
|
||||||
|
|
||||||
__all__ = ['BNPEnterprise']
|
__all__ = ['BNPEnterprise']
|
||||||
|
|
||||||
|
|
@ -32,6 +32,7 @@ class BNPEnterprise(BaseBrowser):
|
||||||
|
|
||||||
PAGES = {'%s://%s/NSAccess.*' % (PROTOCOL, DOMAIN): LoginPage,
|
PAGES = {'%s://%s/NSAccess.*' % (PROTOCOL, DOMAIN): LoginPage,
|
||||||
'%s://%s/UNE\?.*' % (PROTOCOL, DOMAIN): AccountsPage,
|
'%s://%s/UNE\?.*' % (PROTOCOL, DOMAIN): AccountsPage,
|
||||||
|
'%s://%s/ROP\?Action=F_RELCO.+' % (PROTOCOL, DOMAIN): HistoryPage,
|
||||||
'%s://%s/NSFR' % (PROTOCOL, DOMAIN): UnknownPage}
|
'%s://%s/NSFR' % (PROTOCOL, DOMAIN): UnknownPage}
|
||||||
|
|
||||||
def home(self):
|
def home(self):
|
||||||
|
|
@ -61,6 +62,18 @@ class BNPEnterprise(BaseBrowser):
|
||||||
# options shows accounts in their original currency
|
# options shows accounts in their original currency
|
||||||
# it's the "en capitaux" mode, not sure if it's the best
|
# it's the "en capitaux" mode, not sure if it's the best
|
||||||
# the "en valeur" mode is ch8=1000
|
# the "en valeur" mode is ch8=1000
|
||||||
self.location('/UNE?ch6=0&ch8=2000&chA=1&chh=O')
|
if not self.is_on_page(AccountsPage):
|
||||||
|
self.location('/UNE?ch6=0&ch8=2000&chA=1&chh=O')
|
||||||
for account in self.page.get_list():
|
for account in self.page.get_list():
|
||||||
yield account
|
yield account
|
||||||
|
|
||||||
|
def get_account(self, _id):
|
||||||
|
for a in self.get_accounts_list():
|
||||||
|
if a.id == _id:
|
||||||
|
yield a
|
||||||
|
|
||||||
|
def iter_history(self, account):
|
||||||
|
if not self.is_on_page(HistoryPage):
|
||||||
|
self.location('/ROP?Action=F_RELCO&ch4=%s&ch8=2000' % account._link_id)
|
||||||
|
for transaction in self.page.iter_history():
|
||||||
|
yield transaction
|
||||||
|
|
|
||||||
|
|
@ -122,9 +122,7 @@ class AccountsPage(BEPage):
|
||||||
|
|
||||||
def get_list(self):
|
def get_list(self):
|
||||||
table = self.find_table()
|
table = self.find_table()
|
||||||
# skip first tr
|
for tr in self.parser.select(table, 'tr', 'many'):
|
||||||
trs = self.parser.select(table, 'tr')
|
|
||||||
for tr in trs:
|
|
||||||
tds = self.parser.select(tr, 'td')
|
tds = self.parser.select(tr, 'td')
|
||||||
if len(tds) != 6:
|
if len(tds) != 6:
|
||||||
continue
|
continue
|
||||||
|
|
@ -149,5 +147,41 @@ class AccountsPage(BEPage):
|
||||||
yield account
|
yield account
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryPage(BEPage):
|
||||||
|
def is_empty(self):
|
||||||
|
for td in self.parser.select(self.document.getroot(), 'td.V11vertGras'):
|
||||||
|
if u'Aucune opération enregistrée' in to_unicode(td.text_content()):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def find_table(self):
|
||||||
|
for table in self.parser.select(self.document.getroot(), 'table', 'many'):
|
||||||
|
for td in self.parser.select(table, 'tr td'):
|
||||||
|
if td.text_content().strip() == 'OPERATIONS':
|
||||||
|
return table
|
||||||
|
|
||||||
|
def iter_history(self):
|
||||||
|
if not self.is_empty():
|
||||||
|
table = self.find_table()
|
||||||
|
for i, tr in enumerate(self.parser.select(table, 'tr', 'many')):
|
||||||
|
tds = self.parser.select(tr, 'td')
|
||||||
|
if len(tds) != 5 or self.parser.select(tr, 'td.thtitrefondbleu'):
|
||||||
|
continue
|
||||||
|
tddate, tdval, tdlabel, tddebit, tdcredit = \
|
||||||
|
[t.text_content().replace(u'\xa0', ' ').strip() for t in tds]
|
||||||
|
if all((tddate, tdlabel, any((tddebit, tdcredit)))):
|
||||||
|
if tddebit:
|
||||||
|
tdamount = '- %s' % tddebit
|
||||||
|
else:
|
||||||
|
tdamount = tdcredit
|
||||||
|
t = Transaction(i)
|
||||||
|
t.set_amount(tdamount)
|
||||||
|
date = datetime.strptime(tddate, '%d/%m/%Y')
|
||||||
|
val = datetime.strptime(tdval, '%d/%m/%Y')
|
||||||
|
t.parse(date, tdlabel)
|
||||||
|
t._val = val # FIXME is it rdate? date?
|
||||||
|
yield t
|
||||||
|
|
||||||
|
|
||||||
class UnknownPage(BEPage):
|
class UnknownPage(BEPage):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue