fix parsing of card accounts in particular cases
This commit is contained in:
parent
bd110e2e90
commit
19807e1f96
1 changed files with 13 additions and 8 deletions
|
|
@ -103,6 +103,8 @@ class _AccountsPage(BasePage):
|
||||||
yield account
|
yield account
|
||||||
|
|
||||||
def cards_pages(self):
|
def cards_pages(self):
|
||||||
|
# Use a set because it is possible to see several times the same link.
|
||||||
|
links = set()
|
||||||
for line in self.document.xpath('//table[@class="ca-table"]/tr[@class="ligne-connexe"]'):
|
for line in self.document.xpath('//table[@class="ca-table"]/tr[@class="ligne-connexe"]'):
|
||||||
try:
|
try:
|
||||||
link = line.xpath('.//a/@href')[0]
|
link = line.xpath('.//a/@href')[0]
|
||||||
|
|
@ -110,27 +112,28 @@ class _AccountsPage(BasePage):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if not link.startswith('javascript:'):
|
if not link.startswith('javascript:'):
|
||||||
yield link
|
links.add(link)
|
||||||
|
return links
|
||||||
|
|
||||||
|
|
||||||
class CardsPage(BasePage):
|
class CardsPage(BasePage):
|
||||||
|
|
||||||
def get_list(self):
|
def get_list(self):
|
||||||
TABLE_XPATH = '//table[caption[@class="caption tdb-cartes-caption"]]'
|
TABLE_XPATH = '//table[caption[@class="caption tdb-cartes-caption" or @class="ca-table caption"]]'
|
||||||
|
|
||||||
cards_tables = self.document.xpath(TABLE_XPATH)
|
cards_tables = self.document.xpath(TABLE_XPATH)
|
||||||
|
|
||||||
if cards_tables:
|
if cards_tables:
|
||||||
# There are several cards
|
self.logger.debug('There are several cards')
|
||||||
xpaths = {
|
xpaths = {
|
||||||
'_id': './caption/span[@class="tdb-cartes-num"]',
|
'_id': './caption/span[@class="tdb-cartes-num"]',
|
||||||
'label1': './caption/span[@class="tdb-cartes-carte l30"]',
|
'label1': './caption/span[contains(@class, "tdb-cartes-carte")]',
|
||||||
'label2': './caption/span[@class="tdb-cartes-prop"]',
|
'label2': './caption/span[@class="tdb-cartes-prop"]',
|
||||||
'balance': './/tr[last()]/td[@class="cel-num"]',
|
'balance': './/tr/td[@class="cel-num"]',
|
||||||
'currency': '//table/caption//span/text()[starts-with(.,"Montants en ")]',
|
'currency': '//table/caption//span/text()[starts-with(.,"Montants en ")]',
|
||||||
'link': './/tr//a/@href',
|
'link': './/tr//a/@href[contains(., "fwkaction=Detail")]',
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
self.logger.debug('There is only one card')
|
||||||
xpaths = {
|
xpaths = {
|
||||||
'_id': './/tr/td[@class="cel-texte"]',
|
'_id': './/tr/td[@class="cel-texte"]',
|
||||||
'label1': './/tr[@class="ligne-impaire ligne-bleu"]/th',
|
'label1': './/tr[@class="ligne-impaire ligne-bleu"]/th',
|
||||||
|
|
@ -149,7 +152,7 @@ class CardsPage(BasePage):
|
||||||
account.label = '%s - %s' % (get('label1'),
|
account.label = '%s - %s' % (get('label1'),
|
||||||
re.sub('\s*-\s*$', '', get('label2')))
|
re.sub('\s*-\s*$', '', get('label2')))
|
||||||
try:
|
try:
|
||||||
account.balance = Decimal(Transaction.clean_amount(get('balance')))
|
account.balance = Decimal(Transaction.clean_amount(table.xpath(xpaths['balance'])[-1].text))
|
||||||
account.currency = account.get_currency(self.document
|
account.currency = account.get_currency(self.document
|
||||||
.xpath(xpaths['currency'])[0].replace("Montants en ", ""))
|
.xpath(xpaths['currency'])[0].replace("Montants en ", ""))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
@ -160,6 +163,8 @@ class CardsPage(BasePage):
|
||||||
account._link = table.xpath(xpaths['link'])[-1]
|
account._link = table.xpath(xpaths['link'])[-1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
account._link = None
|
account._link = None
|
||||||
|
else:
|
||||||
|
account._link = re.sub('[\n\r\t]+', '', account._link)
|
||||||
else:
|
else:
|
||||||
account._link = self.url
|
account._link = self.url
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue