bpent: support coming transactions
This commit is contained in:
parent
63648a8353
commit
26ebea7875
3 changed files with 41 additions and 27 deletions
|
|
@ -101,9 +101,6 @@ class BNPorcBackend(BaseBackend, ICapBank, ICapMessages):
|
|||
return self.browser.iter_history(account)
|
||||
|
||||
def iter_coming(self, account):
|
||||
if self.config['website'].get() != 'pp':
|
||||
raise NotImplementedError()
|
||||
|
||||
with self.browser:
|
||||
return self.browser.iter_coming_operations(account)
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class BNPEnterprise(BaseBrowser):
|
|||
PAGES = {'%s://%s/NSAccess.*' % (PROTOCOL, DOMAIN): LoginPage,
|
||||
'%s://%s/UNE\?.*' % (PROTOCOL, DOMAIN): AccountsPage,
|
||||
'%s://%s/ROP\?Action=F_RELCO.+' % (PROTOCOL, DOMAIN): HistoryPage,
|
||||
'%s://%s/RLOPI\?.+' % (PROTOCOL, DOMAIN): HistoryPage,
|
||||
'%s://%s/NSFR' % (PROTOCOL, DOMAIN): UnknownPage}
|
||||
|
||||
def home(self):
|
||||
|
|
@ -80,5 +81,13 @@ class BNPEnterprise(BaseBrowser):
|
|||
d1, d2 = self.page.get_date_range()
|
||||
self.location('/ROP?Action=F_RELCO&ch4=%s&ch5=%s&ch9=%s&ch8=2000' % (account._link_id, d1, d2))
|
||||
|
||||
for transaction in self.page.iter_history():
|
||||
yield transaction
|
||||
return self.page.iter_history()
|
||||
|
||||
def iter_coming_operations(self, account):
|
||||
if account._link_id is None:
|
||||
return
|
||||
|
||||
# XXX change date here
|
||||
self.location('/RLOPI?chC=%s&ch8=0000&chB=1&ch7=30/06/2013&ch9=18/09/2013' % account.id)
|
||||
|
||||
return self.page.iter_history(only_coming=True)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from decimal import Decimal
|
|||
import hashlib
|
||||
from urlparse import parse_qs
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.browser import BasePage, BrokenPageError
|
||||
|
|
@ -162,7 +163,7 @@ class HistoryPage(BEPage):
|
|||
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':
|
||||
if re.search('^OP.RATION', td.text_content().strip()):
|
||||
return table
|
||||
|
||||
def get_date_range(self):
|
||||
|
|
@ -171,27 +172,34 @@ class HistoryPage(BEPage):
|
|||
d2 = radio.attrib['value'][10:20]
|
||||
return (d1, d2)
|
||||
|
||||
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.vdate = val
|
||||
yield t
|
||||
def iter_history(self, only_coming=False):
|
||||
if self.is_empty():
|
||||
return
|
||||
|
||||
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 tds[0].find('span') is None and only_coming:
|
||||
# coming
|
||||
continue
|
||||
|
||||
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.vdate = val
|
||||
yield t
|
||||
|
||||
|
||||
class UnknownPage(BEPage):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue