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
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']
|
||||
Loading…
Add table
Add a link
Reference in a new issue