Bank: Add Delubac
This commit is contained in:
parent
0cf4148f36
commit
93cd71e193
5 changed files with 308 additions and 0 deletions
109
modules/delubac/pages.py
Normal file
109
modules/delubac/pages.py
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2013 Noe Rubinstein
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from decimal import Decimal
|
||||
import re
|
||||
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||
|
||||
|
||||
__all__ = ['LoginPage', 'DashboardPage', 'OperationsPage']
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
|
||||
def login(self, username, password):
|
||||
self.browser.select_form(name="frmLogin")
|
||||
self.browser['username'] = username
|
||||
self.browser['password'] = password
|
||||
self.browser.find_control('lang').readonly = False
|
||||
self.browser['lang'] = 'fr'
|
||||
self.browser.submit(nologin=True)
|
||||
|
||||
|
||||
class DashboardPage(BasePage):
|
||||
def iter_accounts(self):
|
||||
for line in self._accounts():
|
||||
yield self._get_account(line)
|
||||
|
||||
def get_account(self, _id):
|
||||
xpath = './/a[@href="tbord.do?id=%s"]' % _id
|
||||
account = next(a for a in self._accounts() if a.xpath(xpath))
|
||||
return self._get_account(account)
|
||||
|
||||
def _accounts(self):
|
||||
return self.document.getroot().cssselect('.tbord_account')
|
||||
|
||||
_FIELD_XPATH = './/span[@class="%s"]//text()'
|
||||
_URL_XPATH = './/span[@class="accountLabel"]//a/@href'
|
||||
|
||||
def _get_account(self, line):
|
||||
def get_field(field):
|
||||
return unicode(line.xpath(self._FIELD_XPATH % field)[0]).strip()
|
||||
|
||||
account = Account()
|
||||
account._url = unicode(line.xpath(self._URL_XPATH)[0])
|
||||
account.id = account._url.replace("tbord.do?id=", "")
|
||||
account.balance = FrenchTransaction.clean_amount(
|
||||
get_field('accountTotal'))
|
||||
account.label = get_field('accountLabel2')
|
||||
account.currency = Account.TXT2CUR.get(get_field('accountDev'),
|
||||
Account.CUR_UNKNOWN)
|
||||
|
||||
return account
|
||||
|
||||
|
||||
class OperationsPage(BasePage):
|
||||
_LINE_XPATH = '//tr[starts-with(@class,"PL_LIGLST_")]'
|
||||
|
||||
def iter_history(self):
|
||||
i = 0
|
||||
for line in self.document.xpath(self._LINE_XPATH):
|
||||
i += 1
|
||||
operation = Transaction(i)
|
||||
|
||||
date = line.xpath('.//td[@class="nlb d"]')[0].text_content().strip()
|
||||
raw = line.xpath('.//td[@class="t"]')[0].text_content().strip()
|
||||
|
||||
amounts = line.xpath('.//td[@class="n"]')
|
||||
[debit, credit] = [amount.text_content().strip()
|
||||
for amount in line.xpath('.//td[@class="n"]')]
|
||||
|
||||
operation.parse(date=date, raw=raw)
|
||||
operation.set_amount(credit, debit)
|
||||
|
||||
yield operation
|
||||
|
||||
|
||||
class Transaction(FrenchTransaction):
|
||||
PATTERNS = [(re.compile('^(?:Vir(?:ement)?|VRT) (?P<text>.*)', re.I),
|
||||
FrenchTransaction.TYPE_TRANSFER),
|
||||
(re.compile('^CARTE(?: ETR.)? ' +
|
||||
'(?P<dd>\d{2})/(?P<mm>\d{2})/(?P<yy>\d{4}) ' +
|
||||
'(?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_CARD),
|
||||
(re.compile('^CHQ (?P<text>.*)$'),
|
||||
FrenchTransaction.TYPE_CHECK),
|
||||
(re.compile('^RCH (?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_DEPOSIT)]
|
||||
|
||||
_is_coming = False
|
||||
Loading…
Add table
Add a link
Reference in a new issue