support multi-cards pages

This commit is contained in:
Romain Bignon 2013-09-29 17:39:02 +02:00
commit b108bf8a58

View file

@ -252,12 +252,26 @@ class ComingPage(OperationsPage):
class CardPage(OperationsPage): class CardPage(OperationsPage):
def get_history(self): def get_history(self):
index = 0 index = 0
label = self.parser.tocleanstring(self.parser.select(self.document.getroot(), 'div.lister p.c', 1))
# Check if this is a multi-cards page
pages = []
for a in self.document.xpath('//table[@class="liste"]/tbody/tr/td/a'):
card_link = a.get('href')
history_url = 'https://%s/%s/fr/banque/%s' % (self.browser.DOMAIN, self.browser.currentSubBank, card_link)
page = self.browser.get_document(self.browser.openurl(history_url))
pages.append(page)
if len(pages) == 0:
# If not, add this page as transactions list
pages.append(self.document)
for page in pages:
label = self.parser.tocleanstring(self.parser.select(page.getroot(), 'div.lister p.c', 1))
label = re.findall('(\d+ [^ ]+ \d+)', label)[-1] label = re.findall('(\d+ [^ ]+ \d+)', label)[-1]
# use the trick of relativedelta to get the last day of month. # use the trick of relativedelta to get the last day of month.
debit_date = parse_french_date(label) + relativedelta(day=31) debit_date = parse_french_date(label) + relativedelta(day=31)
for tr in self.document.xpath('//table[@class="liste"]/tbody/tr'): for tr in page.xpath('//table[@class="liste"]/tbody/tr'):
tds = tr.findall('td')[:4] tds = tr.findall('td')[:4]
if len(tds) < 4: if len(tds) < 4:
continue continue
@ -276,7 +290,6 @@ class CardPage(OperationsPage):
tr.set_amount(tds[-1].text) tr.set_amount(tds[-1].text)
yield tr yield tr
class NoOperationsPage(OperationsPage): class NoOperationsPage(OperationsPage):
def get_history(self): def get_history(self):
return iter([]) return iter([])