Commit eb55f72d authored by Romain Bignon's avatar Romain Bignon

bnpent: support pagination

parent c3f87ad7
......@@ -73,21 +73,38 @@ class BNPEnterprise(BaseBrowser):
if == _id:
yield a
def _get_history(self, url):
numPage = 1
while numPage is not None:
self.location(url + '&chP=%s' % numPage)
for tr in
yield tr
nextNumPage =
if nextNumPage is not None and nextNumPage <= numPage:
self.logger.error("Currently on page %d, next page cannot be %d!" % (numPage, nextNumPage))
numPage = nextNumPage
def iter_history(self, account):
if account._link_id is None:
self.location('/ROP?Action=F_RELCO&ch4=%s&ch8=2000' % account._link_id)
d1, d2 =
self.location('/ROP?Action=F_RELCO&ch4=%s&ch5=%s&ch9=%s&ch8=2000' % (account._link_id, d1, d2))
return self._get_history('/ROP?Action=F_RELCO&ch4=%s&ch5=%s&ch9=%s&ch8=2000' % (account._link_id, d1, d2))
def iter_coming_operations(self, account):
if account._link_id is None:
# XXX change date here
self.location('/RLOPI?chC=%s&ch8=0000&chB=1&ch7=30/06/2013&ch9=18/09/2013' %
self.location('/RLOPI?chC=%s&ch8=0000' %
d1, d2 =
for tr in self._get_history('/RLOPI?chC=%s&ch8=0000&chB=1&ch7=%s&ch9=%s' % (, d1, d2)):
if tr._coming:
yield tr
......@@ -167,27 +167,51 @@ class HistoryPage(BEPage):
return table
def get_date_range(self):
radio =, '//input[@name="br_tout_date"]', 1, 'xpath')
d1 = radio.attrib['value'][0:10]
d2 = radio.attrib['value'][10:20]
radio =, '//input[@name="br_tout_date"]', 1, 'xpath')
except BrokenPageError:
input = self.document.xpath('//input[@name="chB"]')[0]
print '%r' % input.tail
d1, d2 = re.findall('(\d+/\d+/\d+)', input.tail)
d1 = radio.attrib['value'][0:10]
d2 = radio.attrib['value'][10:20]
return (d1, d2)
def iter_history(self, only_coming=False):
TXT2CONST = {u'DATE VALEUR': 'vdate',
u'DATE D\'OPE': 'date',
u'OP.RATION': 'label',
u'D.BIT': 'debit',
u'CR.DIT': 'credit',
def iter_history(self):
if self.is_empty():
columns = {'date': 0, 'vdate': 1, 'label': 2, 'debit': 3, 'credit': 4}
table = self.find_table()
for i, tr in enumerate(, 'tr', 'many')):
tds =, 'td')
if len(tds) != 5 or, 'td.thtitrefondbleu'):
if len(tds) != 5:
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
if, 'td.thtitrefondbleu'):
for i, td in enumerate(tds):
txt = self.parser.tocleanstring(td)
for part, const in self.TXT2CONST.iteritems():
if, txt):
columns[const] = i
tddate = self.parser.tocleanstring(tds[columns['date']])
tdval = self.parser.tocleanstring(tds[columns['vdate']])
tdlabel = self.parser.tocleanstring(tds[columns['label']])
tddebit = self.parser.tocleanstring(tds[columns['debit']])
tdcredit = self.parser.tocleanstring(tds[columns['credit']])
if all((tddate, tdlabel, any((tddebit, tdcredit)))):
if tddebit:
tdamount = '- %s' % tddebit
......@@ -195,12 +219,40 @@ class HistoryPage(BEPage):
tdamount = tdcredit
t = Transaction(i)
date = datetime.strptime(tddate, '%d/%m/%Y')
val = datetime.strptime(tdval, '%d/%m/%Y')
t.parse(date, tdlabel)
t.vdate = val
t.parse(tddate, tdlabel, tdval)
t._coming = (tds[0].find('span') is not None)
yield t
def get_next_numpage(self):
current = 1
m ='chP=(\d+)', self.url)
if m:
current = int(
pages = self.parser.tocleanstring(self.document.xpath('.//td[contains(text(), "Page")]')[0])
except IndexError:
# No pagination
return None
# We get list of all page numbers...
pages = sorted(map(int, re.findall('(\d+)', pages)))
# ...find position of the current page...
curidx = pages.index(current)
except ValueError:
self.logger.warning('Unable to find the current page (%d)' % current)
return None
# ... and return number of the next page
return pages[curidx+1]
except IndexError:
# Last page
return None
class UnknownPage(BEPage):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment