cragr: fix parsing cards
This commit is contained in:
parent
ba40529b3b
commit
04df80d22b
1 changed files with 20 additions and 14 deletions
|
|
@ -22,7 +22,7 @@ from decimal import Decimal
|
||||||
|
|
||||||
from weboob.tools.date import parse_french_date
|
from weboob.tools.date import parse_french_date
|
||||||
from weboob.capabilities.bank import Account
|
from weboob.capabilities.bank import Account
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage, BrokenPageError
|
||||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction
|
from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -146,11 +146,18 @@ class CardsPage(BasePage):
|
||||||
account.id = ''.join(get('_id').split()[1:])
|
account.id = ''.join(get('_id').split()[1:])
|
||||||
account.label = '%s - %s' % (get('label1'),
|
account.label = '%s - %s' % (get('label1'),
|
||||||
re.sub('\s*-\s*$', '', get('label2')))
|
re.sub('\s*-\s*$', '', get('label2')))
|
||||||
account.balance = Decimal(Transaction.clean_amount(get('balance')))
|
try:
|
||||||
account.currency = account.get_currency(self.document
|
account.balance = Decimal(Transaction.clean_amount(get('balance')))
|
||||||
.xpath(xpaths['currency'])[0].replace("Montants en ", ""))
|
account.currency = account.get_currency(self.document
|
||||||
|
.xpath(xpaths['currency'])[0].replace("Montants en ", ""))
|
||||||
|
except IndexError:
|
||||||
|
account.balance = Decimal('0.0')
|
||||||
|
|
||||||
if 'link' in xpaths:
|
if 'link' in xpaths:
|
||||||
account._link = table.xpath(xpaths['link'])[-1]
|
try:
|
||||||
|
account._link = table.xpath(xpaths['link'])[-1]
|
||||||
|
except IndexError:
|
||||||
|
account._link = None
|
||||||
else:
|
else:
|
||||||
account._link = self.url
|
account._link = self.url
|
||||||
|
|
||||||
|
|
@ -166,21 +173,20 @@ class CardsPage(BasePage):
|
||||||
[date, label, _, amount] = [self.parser.tocleanstring(td)
|
[date, label, _, amount] = [self.parser.tocleanstring(td)
|
||||||
for td in line.xpath('./td')]
|
for td in line.xpath('./td')]
|
||||||
|
|
||||||
clean_amount = Decimal(Transaction.clean_amount(amount))
|
|
||||||
|
|
||||||
t = Transaction(0)
|
t = Transaction(0)
|
||||||
|
t.set_amount(amount)
|
||||||
|
t.label = t.raw = label
|
||||||
|
|
||||||
if is_balance:
|
if is_balance:
|
||||||
date_str = label.replace( u"Opérations débitées le ", "") \
|
m = re.search('(\d+ [^ ]+ \d+)', label)
|
||||||
.replace(" :","")
|
if not m:
|
||||||
t.date = parse_french_date(date_str)
|
raise BrokenPageError('Unable to read card balance in history: %r' % label)
|
||||||
t.label = u"Débit"
|
|
||||||
t.amount = -clean_amount
|
t.date = parse_french_date(m.group(1))
|
||||||
|
t.amount = -t.amount
|
||||||
else:
|
else:
|
||||||
day, month = map(int, date.split('/', 1))
|
day, month = map(int, date.split('/', 1))
|
||||||
t.date = date_guesser.guess_date(day, month)
|
t.date = date_guesser.guess_date(day, month)
|
||||||
t.label = t.raw = label
|
|
||||||
t.amount = clean_amount
|
|
||||||
|
|
||||||
t.type = t.TYPE_CARD
|
t.type = t.TYPE_CARD
|
||||||
t.rdate = t.date
|
t.rdate = t.date
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue