support repositories to manage backends (closes #747)
This commit is contained in:
parent
ef16a5b726
commit
14a7a1d362
410 changed files with 1079 additions and 297 deletions
23
modules/bnporc/__init__.py
Normal file
23
modules/bnporc/__init__.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Romain Bignon
|
||||
#
|
||||
# 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 .backend import BNPorcBackend
|
||||
|
||||
__all__ = ['BNPorcBackend']
|
||||
106
modules/bnporc/backend.py
Normal file
106
modules/bnporc/backend.py
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound, Account, Recipient
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import ValueBackendPassword
|
||||
|
||||
from .browser import BNPorc
|
||||
|
||||
|
||||
__all__ = ['BNPorcBackend']
|
||||
|
||||
|
||||
class BNPorcBackend(BaseBackend, ICapBank):
|
||||
NAME = 'bnporc'
|
||||
MAINTAINER = 'Romain Bignon'
|
||||
EMAIL = 'romain@weboob.org'
|
||||
VERSION = '0.a'
|
||||
LICENSE = 'AGPLv3+'
|
||||
DESCRIPTION = 'BNP Paribas french bank\' website'
|
||||
CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False),
|
||||
ValueBackendPassword('password', label='Password', regexp='^(\d{6}|)$'),
|
||||
ValueBackendPassword('rotating_password',
|
||||
label='Password to set when the allowed uses are exhausted (6 digits)',
|
||||
regexp='^(\d{6}|)$'))
|
||||
BROWSER = BNPorc
|
||||
|
||||
def create_default_browser(self):
|
||||
if self.config['rotating_password'].get().isdigit() and len(self.config['rotating_password'].get()) == 6:
|
||||
rotating_password = self.config['rotating_password'].get()
|
||||
else:
|
||||
rotating_password = None
|
||||
return self.create_browser(self.config['login'].get(),
|
||||
self.config['password'].get(),
|
||||
password_changed_cb=self._password_changed_cb,
|
||||
rotating_password=rotating_password)
|
||||
|
||||
def _password_changed_cb(self, old, new):
|
||||
self.config['password'].set(new)
|
||||
self.config['rotating_password'].set(old)
|
||||
self.config.save()
|
||||
|
||||
def iter_accounts(self):
|
||||
for account in self.browser.get_accounts_list():
|
||||
yield account
|
||||
|
||||
def get_account(self, _id):
|
||||
if not _id.isdigit():
|
||||
raise AccountNotFound()
|
||||
with self.browser:
|
||||
account = self.browser.get_account(_id)
|
||||
if account:
|
||||
return account
|
||||
else:
|
||||
raise AccountNotFound()
|
||||
|
||||
def iter_history(self, account):
|
||||
with self.browser:
|
||||
for history in self.browser.get_history(account):
|
||||
yield history
|
||||
|
||||
def iter_operations(self, account):
|
||||
with self.browser:
|
||||
for coming in self.browser.get_coming_operations(account):
|
||||
yield coming
|
||||
|
||||
def iter_transfer_recipients(self, ignored):
|
||||
for account in self.browser.get_transfer_accounts().itervalues():
|
||||
recipient = Recipient()
|
||||
recipient.id = account.id
|
||||
recipient.label = account.label
|
||||
yield recipient
|
||||
|
||||
def transfer(self, account, to, amount, reason=None):
|
||||
if isinstance(account, Account):
|
||||
account = account.id
|
||||
|
||||
try:
|
||||
assert account.isdigit()
|
||||
assert to.isdigit()
|
||||
amount = float(amount)
|
||||
except (AssertionError, ValueError):
|
||||
raise AccountNotFound()
|
||||
|
||||
with self.browser:
|
||||
return self.browser.transfer(account, to, amount, reason)
|
||||
158
modules/bnporc/browser.py
Normal file
158
modules/bnporc/browser.py
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon
|
||||
#
|
||||
# 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 datetime import datetime
|
||||
from logging import warning
|
||||
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
from weboob.capabilities.bank import TransferError, Transfer
|
||||
from bnporc import pages
|
||||
from .errors import PasswordExpired
|
||||
|
||||
|
||||
__all__ = ['BNPorc']
|
||||
|
||||
|
||||
class BNPorc(BaseBrowser):
|
||||
DOMAIN = 'www.secure.bnpparibas.net'
|
||||
PROTOCOL = 'https'
|
||||
ENCODING = None # refer to the HTML encoding
|
||||
PAGES = {'.*identifiant=DOSSIER_Releves_D_Operation.*': pages.AccountsList,
|
||||
'.*SAF_ROP.*': pages.AccountHistory,
|
||||
'.*Action=SAF_CHM.*': pages.ChangePasswordPage,
|
||||
'.*NS_AVEDT.*': pages.AccountComing,
|
||||
'.*NS_AVEDP.*': pages.AccountPrelevement,
|
||||
'.*NS_VIRDF.*': pages.TransferPage,
|
||||
'.*NS_VIRDC.*': pages.TransferConfirmPage,
|
||||
'.*/NS_VIRDA\?stp=(?P<id>\d+).*': pages.TransferCompletePage,
|
||||
'.*Action=DSP_VGLOBALE.*': pages.LoginPage,
|
||||
'.*type=homeconnex.*': pages.LoginPage,
|
||||
'.*layout=HomeConnexion.*': pages.ConfirmPage,
|
||||
'.*SAF_CHM_VALID.*': pages.ConfirmPage,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.rotating_password = kwargs.pop('rotating_password', None)
|
||||
self.password_changed_cb = kwargs.pop('password_changed_cb', None)
|
||||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
|
||||
def home(self):
|
||||
self.location('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex')
|
||||
|
||||
def is_logged(self):
|
||||
return not self.is_on_page(pages.LoginPage)
|
||||
|
||||
def login(self):
|
||||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
assert self.password.isdigit()
|
||||
|
||||
if not self.is_on_page(pages.LoginPage):
|
||||
self.location('https://www.secure.bnpparibas.net/banque/portail/particulier/HomeConnexion?type=homeconnex')
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
self.location('/NSFR?Action=DSP_VGLOBALE', no_login=True)
|
||||
|
||||
if self.is_on_page(pages.LoginPage):
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
def change_password(self, new_password):
|
||||
assert new_password.isdigit() and len(new_password) == 6
|
||||
|
||||
self.location('https://www.secure.bnpparibas.net/SAF_CHM?Action=SAF_CHM')
|
||||
assert self.is_on_page(pages.ChangePasswordPage)
|
||||
|
||||
self.page.change_password(self.password, new_password)
|
||||
|
||||
if not self.is_on_page(pages.ConfirmPage):
|
||||
self.logger.error('Oops, unable to change password')
|
||||
return
|
||||
|
||||
self.password, self.rotating_password = (new_password, self.password)
|
||||
|
||||
if self.password_changed_cb:
|
||||
self.password_changed_cb(self.rotating_password, self.password)
|
||||
|
||||
def check_expired_password(func):
|
||||
def inner(self, *args, **kwargs):
|
||||
try:
|
||||
return func(self, *args, **kwargs)
|
||||
except PasswordExpired:
|
||||
if self.rotating_password is not None:
|
||||
warning('[%s] Your password has expired. Switching...' % self.username)
|
||||
self.change_password(self.rotating_password)
|
||||
return func(self, *args, **kwargs)
|
||||
else:
|
||||
raise
|
||||
return inner
|
||||
|
||||
@check_expired_password
|
||||
def get_accounts_list(self):
|
||||
if not self.is_on_page(pages.AccountsList):
|
||||
self.location('/NSFR?Action=DSP_VGLOBALE')
|
||||
|
||||
return self.page.get_list()
|
||||
|
||||
def get_account(self, id):
|
||||
assert isinstance(id, basestring)
|
||||
|
||||
if not self.is_on_page(pages.AccountsList):
|
||||
self.location('/NSFR?Action=DSP_VGLOBALE')
|
||||
|
||||
l = self.page.get_list()
|
||||
for a in l:
|
||||
if a.id == id:
|
||||
return a
|
||||
|
||||
return None
|
||||
|
||||
def get_history(self, account):
|
||||
if not self.is_on_page(pages.AccountHistory) or self.page.account.id != account.id:
|
||||
self.location('/SAF_ROP?ch4=%s' % account.link_id)
|
||||
return self.page.get_operations()
|
||||
|
||||
def get_coming_operations(self, account):
|
||||
if not self.is_on_page(pages.AccountComing) or self.page.account.id != account.id:
|
||||
self.location('/NS_AVEDT?ch4=%s' % account.link_id)
|
||||
return self.page.get_operations()
|
||||
|
||||
def get_transfer_accounts(self):
|
||||
if not self.is_on_page(pages.TransferPage):
|
||||
self.location('/NS_VIRDF')
|
||||
|
||||
assert self.is_on_page(pages.TransferPage)
|
||||
return self.page.get_accounts()
|
||||
|
||||
def transfer(self, from_id, to_id, amount, reason=None):
|
||||
if not self.is_on_page(pages.TransferPage):
|
||||
self.location('/NS_VIRDF')
|
||||
|
||||
accounts = self.page.get_accounts()
|
||||
self.page.transfer(from_id, to_id, amount, reason)
|
||||
|
||||
if not self.is_on_page(pages.TransferCompletePage):
|
||||
raise TransferError('An error occured during transfer')
|
||||
|
||||
transfer = Transfer(self.page.get_id())
|
||||
transfer.amount = amount
|
||||
transfer.origin = accounts[from_id].label
|
||||
transfer.recipient = accounts[to_id].label
|
||||
transfer.date = datetime.now()
|
||||
return transfer
|
||||
25
modules/bnporc/errors.py
Normal file
25
modules/bnporc/errors.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
__all__ = ['PasswordExpired']
|
||||
|
||||
|
||||
class PasswordExpired(Exception):
|
||||
pass
|
||||
BIN
modules/bnporc/favicon.png
Normal file
BIN
modules/bnporc/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
31
modules/bnporc/pages/__init__.py
Normal file
31
modules/bnporc/pages/__init__.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon
|
||||
#
|
||||
# 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 .accounts_list import AccountsList
|
||||
from .account_coming import AccountComing
|
||||
from .account_history import AccountHistory
|
||||
from .transfer import TransferPage, TransferConfirmPage, TransferCompletePage
|
||||
from .login import LoginPage, ConfirmPage, ChangePasswordPage
|
||||
|
||||
class AccountPrelevement(AccountsList): pass
|
||||
|
||||
__all__ = ['AccountsList', 'AccountComing', 'AccountHistory', 'LoginPage',
|
||||
'ConfirmPage', 'AccountPrelevement', 'ChangePasswordPage',
|
||||
'TransferPage', 'TransferConfirmPage', 'TransferCompletePage']
|
||||
71
modules/bnporc/pages/account_coming.py
Normal file
71
modules/bnporc/pages/account_coming.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
import re
|
||||
from datetime import date
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.bank import Operation
|
||||
|
||||
|
||||
__all__ = ['AccountComing']
|
||||
|
||||
|
||||
class AccountComing(BasePage):
|
||||
LABEL_PATTERNS = [('^FACTURECARTEDU(?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})(?P<text>.*)',
|
||||
u'CB %(yy)s-%(mm)s-%(dd)s: %(text)s'),
|
||||
('^PRELEVEMENT(?P<text>.*)', 'Order: %(text)s'),
|
||||
('^ECHEANCEPRET(?P<text>.*)', u'Loan payment n°%(text)s'),
|
||||
]
|
||||
|
||||
def on_loaded(self):
|
||||
self.operations = []
|
||||
|
||||
for tr in self.document.getiterator('tr'):
|
||||
if tr.attrib.get('class', '') == 'hdoc1' or tr.attrib.get('class', '') == 'hdotc1':
|
||||
tds = tr.findall('td')
|
||||
if len(tds) != 3:
|
||||
continue
|
||||
d = tds[0].getchildren()[0].attrib.get('name', '')
|
||||
d = date(int(d[0:4]), int(d[4:6]), int(d[6:8]))
|
||||
label = u''
|
||||
label += tds[1].text or u''
|
||||
label = label.replace(u'\xa0', u'')
|
||||
for child in tds[1].getchildren():
|
||||
if child.text: label += child.text
|
||||
if child.tail: label += child.tail
|
||||
if tds[1].tail: label += tds[1].tail
|
||||
label = label.strip()
|
||||
|
||||
for pattern, text in self.LABEL_PATTERNS:
|
||||
m = re.match(pattern, label)
|
||||
if m:
|
||||
label = text % m.groupdict()
|
||||
|
||||
amount = tds[2].text.replace('.', '').replace(',', '.')
|
||||
|
||||
operation = Operation(len(self.operations))
|
||||
operation.date = d
|
||||
operation.label = label
|
||||
operation.amount = float(amount)
|
||||
self.operations.append(operation)
|
||||
|
||||
def get_operations(self):
|
||||
return self.operations
|
||||
80
modules/bnporc/pages/account_history.py
Normal file
80
modules/bnporc/pages/account_history.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
import re
|
||||
from datetime import date
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.bank import Operation
|
||||
from weboob.capabilities.base import NotAvailable
|
||||
|
||||
|
||||
__all__ = ['AccountHistory']
|
||||
|
||||
|
||||
class AccountHistory(BasePage):
|
||||
LABEL_PATTERNS = [(u'^CHEQUEN°(?P<no>.*)', u'CHEQUE', u'N°%(no)s')]
|
||||
|
||||
def on_loaded(self):
|
||||
self.operations = []
|
||||
|
||||
for tr in self.document.getiterator('tr'):
|
||||
if tr.attrib.get('class', '') == 'hdoc1' or tr.attrib.get('class', '') == 'hdotc1':
|
||||
tds = tr.findall('td')
|
||||
if len(tds) != 4:
|
||||
continue
|
||||
d = date(*reversed([int(x) for x in tds[0].text.split('/')]))
|
||||
label = u''
|
||||
label += tds[1].text
|
||||
label = label.replace(u'\xa0', u'')
|
||||
for child in tds[1].getchildren():
|
||||
if child.text: label += child.text
|
||||
if child.tail: label += child.tail
|
||||
if tds[1].tail: label += tds[1].tail
|
||||
|
||||
label = label.strip()
|
||||
category = NotAvailable
|
||||
for pattern, _cat, _lab in self.LABEL_PATTERNS:
|
||||
m = re.match(pattern, label)
|
||||
if m:
|
||||
category = _cat % m.groupdict()
|
||||
label = _lab % m.groupdict()
|
||||
break
|
||||
else:
|
||||
if ' ' in label:
|
||||
category, useless, label = [part.strip() for part in label.partition(' ')]
|
||||
|
||||
amount = tds[2].text.replace('.', '').replace(',', '.')
|
||||
|
||||
# if we don't have exactly one '.', this is not a floatm try the next
|
||||
operation = Operation(len(self.operations))
|
||||
if amount.count('.') != 1:
|
||||
amount = tds[3].text.replace('.', '').replace(',', '.')
|
||||
operation.amount = float(amount)
|
||||
else:
|
||||
operation.amount = - float(amount)
|
||||
|
||||
operation.date = d
|
||||
operation.label = label
|
||||
operation.category = category
|
||||
self.operations.append(operation)
|
||||
|
||||
def get_operations(self):
|
||||
return self.operations
|
||||
78
modules/bnporc/pages/accounts_list.py
Normal file
78
modules/bnporc/pages/accounts_list.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
import re
|
||||
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.capabilities.base import NotAvailable
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
from ..errors import PasswordExpired
|
||||
|
||||
|
||||
__all__ = ['AccountsList']
|
||||
|
||||
|
||||
class AccountsList(BasePage):
|
||||
LINKID_REGEXP = re.compile(".*ch4=(\w+).*")
|
||||
|
||||
def on_loaded(self):
|
||||
pass
|
||||
|
||||
def get_list(self):
|
||||
l = []
|
||||
for tr in self.document.getiterator('tr'):
|
||||
if tr.attrib.get('class', '') == 'comptes':
|
||||
account = Account()
|
||||
for td in tr.getiterator('td'):
|
||||
if td.attrib.get('headers', '').startswith('Numero_'):
|
||||
id = td.text
|
||||
account.id = ''.join(id.split(' ')).strip()
|
||||
elif td.attrib.get('headers', '').startswith('Libelle_'):
|
||||
a = td.findall('a')
|
||||
label = unicode(a[0].text)
|
||||
account.label = label.strip()
|
||||
m = self.LINKID_REGEXP.match(a[0].attrib.get('href', ''))
|
||||
if m:
|
||||
account.link_id = m.group(1)
|
||||
elif td.attrib.get('headers', '').startswith('Solde'):
|
||||
a = td.findall('a')
|
||||
balance = a[0].text
|
||||
balance = balance.replace('.','').replace(',','.')
|
||||
account.balance = float(balance)
|
||||
elif td.attrib.get('headers', '').startswith('Avenir'):
|
||||
a = td.findall('a')
|
||||
# Some accounts don't have a "coming"
|
||||
if len(a):
|
||||
coming = a[0].text
|
||||
coming = coming.replace('.','').replace(',','.')
|
||||
account.coming = float(coming)
|
||||
else:
|
||||
account.coming = NotAvailable
|
||||
|
||||
l.append(account)
|
||||
|
||||
if len(l) == 0:
|
||||
# oops, no accounts? check if we have not exhausted the allowed use
|
||||
# of this password
|
||||
for div in self.document.getroot().cssselect('div.Style_texte_gras'):
|
||||
if div.text.strip() == 'Vous avez atteint la date de fin de vie de votre code secret.':
|
||||
raise PasswordExpired(div.text.strip())
|
||||
return l
|
||||
114
modules/bnporc/pages/login.py
Normal file
114
modules/bnporc/pages/login.py
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2009-2011 Romain Bignon, Pierre Mazière
|
||||
#
|
||||
# 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 weboob.tools.mech import ClientForm
|
||||
import urllib
|
||||
from logging import error
|
||||
|
||||
from weboob.tools.browser import BasePage, BrowserUnavailable
|
||||
from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard,VirtKeyboardError
|
||||
import tempfile
|
||||
|
||||
__all__ = ['LoginPage', 'ConfirmPage', 'ChangePasswordPage']
|
||||
|
||||
class BNPVirtKeyboard(MappedVirtKeyboard):
|
||||
symbols={'0':'9cc4789a2cb223e8f2d5e676e90264b5',
|
||||
'1':'e10b58fc085f9683052d5a63c96fc912',
|
||||
'2':'04ec647e7b3414bcc069f0c54eb55a4c',
|
||||
'3':'fde84fd9bac725db8463554448f1e469',
|
||||
'4':'2359eea8671bf112b58264bec0294f71',
|
||||
'5':'82b55b63480114f04fad8c5c4fa5673a',
|
||||
'6':'e074864faeaeabb3be3d118192cd8879',
|
||||
'7':'af5740e4ca71fadc6f4ae1412d864a1c',
|
||||
'8':'cab759c574038ad89a0e35cc76ab7214',
|
||||
'9':'828cf0faf86ac78e7f43208907620527'
|
||||
}
|
||||
|
||||
url="/NSImgGrille"
|
||||
|
||||
color=27
|
||||
|
||||
def __init__(self,basepage):
|
||||
img=basepage.document.find("//img[@usemap='#MapGril']")
|
||||
MappedVirtKeyboard.__init__(self,basepage.browser.openurl(self.url),basepage.document,img,self.color)
|
||||
if basepage.browser.responses_dirname is None:
|
||||
basepage.browser.responses_dirname = \
|
||||
tempfile.mkdtemp(prefix='weboob_session_')
|
||||
self.check_symbols(self.symbols,basepage.browser.responses_dirname)
|
||||
|
||||
def get_symbol_code(self,md5sum):
|
||||
code=MappedVirtKeyboard.get_symbol_code(self,md5sum)
|
||||
return code[-4:-2]
|
||||
|
||||
def get_string_code(self,string):
|
||||
code=''
|
||||
for c in string:
|
||||
code+=self.get_symbol_code(self.symbols[c])
|
||||
return code
|
||||
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def on_loaded(self):
|
||||
for td in self.document.getroot().cssselect('td.LibelleErreur'):
|
||||
if td.text is None:
|
||||
continue
|
||||
msg = td.text.strip()
|
||||
if 'indisponible' in msg:
|
||||
raise BrowserUnavailable(msg)
|
||||
|
||||
def login(self, login, password):
|
||||
try:
|
||||
vk=BNPVirtKeyboard(self)
|
||||
except VirtKeyboardError,err:
|
||||
error("Error: %s"%err)
|
||||
return False
|
||||
|
||||
self.browser.select_form('logincanalnet')
|
||||
# HACK because of fucking malformed HTML, the field isn't recognized by mechanize.
|
||||
self.browser.controls.append(ClientForm.TextControl('text', 'ch1', {'value': ''}))
|
||||
self.browser.set_all_readonly(False)
|
||||
|
||||
self.browser['ch1'] = login
|
||||
self.browser['ch5'] = vk.get_string_code(password)
|
||||
self.browser.submit()
|
||||
|
||||
|
||||
class ConfirmPage(BasePage):
|
||||
pass
|
||||
|
||||
|
||||
class ChangePasswordPage(BasePage):
|
||||
def change_password(self, current, new):
|
||||
try:
|
||||
vk=BNPVirtKeyboard(self)
|
||||
except VirtKeyboardError,err:
|
||||
error("Error: %s"%err)
|
||||
return False
|
||||
|
||||
code_current=vk.get_string_code(current)
|
||||
code_new=vk.get_string_code(new)
|
||||
|
||||
data = {'ch1': code_current,
|
||||
'ch2': code_new,
|
||||
'ch3': code_new
|
||||
}
|
||||
|
||||
self.browser.location('/SAF_CHM_VALID', urllib.urlencode(data))
|
||||
96
modules/bnporc/pages/transfer.py
Normal file
96
modules/bnporc/pages/transfer.py
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
import re
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
from weboob.capabilities.bank import TransferError
|
||||
|
||||
|
||||
__all__ = ['TransferPage', 'TransferConfirmPage', 'TransferCompletePage']
|
||||
|
||||
|
||||
class Account(object):
|
||||
def __init__(self, id, label, send_checkbox, receive_checkbox):
|
||||
self.id = id
|
||||
self.label = label
|
||||
self.send_checkbox = send_checkbox
|
||||
self.receive_checkbox = receive_checkbox
|
||||
|
||||
class TransferPage(BasePage):
|
||||
def get_accounts(self):
|
||||
accounts = OrderedDict()
|
||||
for table in self.document.getiterator('table'):
|
||||
if table.attrib.get('cellspacing') == '2':
|
||||
for tr in table.cssselect('tr.hdoc1, tr.hdotc1'):
|
||||
tds = tr.findall('td')
|
||||
id = tds[1].text.replace(u'\xa0', u'')
|
||||
label = tds[0].text
|
||||
if label is None and tds[0].find('nobr') is not None:
|
||||
label = tds[0].find('nobr').text
|
||||
send_checkbox = tds[4].find('input').attrib['value'] if tds[4].find('input') is not None else None
|
||||
receive_checkbox = tds[5].find('input').attrib['value'] if tds[5].find('input') is not None else None
|
||||
account = Account(id, label, send_checkbox, receive_checkbox)
|
||||
accounts[id] = account
|
||||
return accounts
|
||||
|
||||
def transfer(self, from_id, to_id, amount, reason):
|
||||
accounts = self.get_accounts()
|
||||
|
||||
try:
|
||||
sender = accounts[from_id]
|
||||
except KeyError:
|
||||
raise TransferError('Account %s not found' % from_id)
|
||||
|
||||
try:
|
||||
recipient = accounts[to_id]
|
||||
except KeyError:
|
||||
raise TransferError('Recipient %s not found' % to_id)
|
||||
|
||||
if sender.send_checkbox is None:
|
||||
raise TransferError('Unable to make a transfer from %s' % sender.label)
|
||||
if recipient.receive_checkbox is None:
|
||||
raise TransferError('Unable to make a transfer to %s' % recipient.label)
|
||||
|
||||
self.browser.select_form(nr=0)
|
||||
self.browser['C1'] = [sender.send_checkbox]
|
||||
self.browser['C2'] = [recipient.receive_checkbox]
|
||||
self.browser['T6'] = str(amount).replace('.', ',')
|
||||
if reason:
|
||||
self.browser['T5'] = reason.encode('utf-8')
|
||||
self.browser.submit()
|
||||
|
||||
|
||||
class TransferConfirmPage(BasePage):
|
||||
def on_loaded(self):
|
||||
for td in self.document.getroot().cssselect('td#size2'):
|
||||
raise TransferError(td.text.strip())
|
||||
|
||||
for a in self.document.getiterator('a'):
|
||||
m = re.match('/NSFR\?Action=VIRDA&stp=(\d+)', a.attrib['href'])
|
||||
if m:
|
||||
self.browser.location('/NS_VIRDA?stp=%s' % m.group(1))
|
||||
return
|
||||
|
||||
|
||||
class TransferCompletePage(BasePage):
|
||||
def get_id(self):
|
||||
return self.group_dict['id']
|
||||
31
modules/bnporc/test.py
Normal file
31
modules/bnporc/test.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Romain Bignon
|
||||
#
|
||||
# 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 weboob.tools.test import BackendTest
|
||||
|
||||
class BNPorcTest(BackendTest):
|
||||
BACKEND = 'bnporc'
|
||||
|
||||
def test_bnporc(self):
|
||||
l = list(self.backend.iter_accounts())
|
||||
if len(l) > 0:
|
||||
a = l[0]
|
||||
list(self.backend.iter_operations(a))
|
||||
list(self.backend.iter_history(a))
|
||||
Loading…
Add table
Add a link
Reference in a new issue