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
22
modules/bp/__init__.py
Normal file
22
modules/bp/__init__.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel <nicolas@NicolasDesktop>
|
||||
#
|
||||
# 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 BPBackend
|
||||
|
||||
__all__ = ['BPBackend']
|
||||
66
modules/bp/backend.py
Normal file
66
modules/bp/backend.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import ValueBackendPassword
|
||||
|
||||
from .browser import BPBrowser
|
||||
|
||||
|
||||
__all__ = ['BPBackend']
|
||||
|
||||
|
||||
class BPBackend(BaseBackend, ICapBank):
|
||||
NAME = 'bp'
|
||||
MAINTAINER = 'Nicolas Duhamel'
|
||||
EMAIL = 'nicolas@jombi.fr'
|
||||
VERSION = '0.a'
|
||||
LICENSE = 'AGPLv3+'
|
||||
DESCRIPTION = u'La banque postale, French bank'
|
||||
CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False),
|
||||
ValueBackendPassword('password', label='Password'))
|
||||
BROWSER = BPBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
return self.create_browser(self.config['login'].get(), self.config['password'].get())
|
||||
|
||||
def iter_accounts(self):
|
||||
for account in self.browser.get_accounts_list():
|
||||
yield account
|
||||
|
||||
def get_account(self, _id):
|
||||
account = self.browser.get_account(_id)
|
||||
if account:
|
||||
return account
|
||||
else:
|
||||
raise AccountNotFound()
|
||||
|
||||
def iter_history(self, account):
|
||||
for history in self.browser.get_history(account):
|
||||
yield history
|
||||
|
||||
def transfer(self, id_from, id_to, amount, reason=None):
|
||||
from_account = self.get_account(id_from)
|
||||
to_account = self.get_account(id_to)
|
||||
|
||||
#TODO: retourner le numero du virement
|
||||
#TODO: support the 'reason' parameter
|
||||
return self.browser.make_transfer(from_account, to_account, amount)
|
||||
111
modules/bp/browser.py
Normal file
111
modules/bp/browser.py
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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 weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserBanned
|
||||
|
||||
from .pages import LoginPage, Initident, CheckPassword, repositionnerCheminCourant, BadLoginPage, AccountDesactivate, \
|
||||
AccountList, AccountHistory, \
|
||||
TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary
|
||||
|
||||
from weboob.capabilities.bank import Transfer
|
||||
|
||||
|
||||
__all__ = ['BPBrowser']
|
||||
|
||||
|
||||
class BPBrowser(BaseBrowser):
|
||||
DOMAIN = 'voscomptesenligne.labanquepostale.fr'
|
||||
PROTOCOL = 'https'
|
||||
ENCODING = None # refer to the HTML encoding
|
||||
PAGES = {r'.*wsost/OstBrokerWeb/loginform.*' : LoginPage,
|
||||
r'.*authentification/repositionnerCheminCourant-identif.ea' : repositionnerCheminCourant,
|
||||
r'.*authentification/initialiser-identif.ea' : Initident,
|
||||
r'.*authentification/verifierMotDePasse-identif.ea' : CheckPassword,
|
||||
|
||||
r'.*synthese_assurancesEtComptes/afficheSynthese-synthese\.ea' : AccountList,
|
||||
r'.*synthese_assurancesEtComptes/rechercheContratAssurance-synthese.ea' : AccountList,
|
||||
|
||||
r'.*CCP/releves_ccp/releveCPP-releve_ccp\.ea' : AccountHistory,
|
||||
r'.*CNE/releveCNE/releveCNE-releve_cne\.ea' : AccountHistory,
|
||||
|
||||
r'.*/virementSafran_aiguillage/init-saisieComptes\.ea' : TransferChooseAccounts,
|
||||
r'.*/virementSafran_aiguillage/formAiguillage-saisieComptes\.ea' : CompleteTransfer,
|
||||
r'.*/virementSafran_national/validerVirementNational-virementNational.ea' : TransferConfirm,
|
||||
r'.*/virementSafran_national/confirmerVirementNational-virementNational.ea' : TransferSummary,
|
||||
|
||||
r'.*ost/messages\.CVS\.html\?param=0x132120c8.*' : BadLoginPage,
|
||||
r'.*ost/messages\.CVS\.html\?param=0x132120cb.*' : AccountDesactivate,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['parser'] = ('lxml',)
|
||||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
|
||||
def home(self):
|
||||
self.location('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?TAM_OP=login&'
|
||||
'ERROR_CODE=0x00000000&URL=%2Fvoscomptes%2FcanalXHTML%2Fidentif.ea%3Forigin%3Dparticuliers')
|
||||
|
||||
def is_logged(self):
|
||||
return not self.is_on_page(LoginPage)
|
||||
|
||||
def login(self):
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.location('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?TAM_OP=login&'
|
||||
'ERROR_CODE=0x00000000&URL=%2Fvoscomptes%2FcanalXHTML%2Fidentif.ea%3Forigin%3Dparticuliers',
|
||||
no_login=True)
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
|
||||
if self.is_on_page(BadLoginPage):
|
||||
raise BrowserIncorrectPassword()
|
||||
if self.is_on_page(AccountDesactivate):
|
||||
raise BrowserBanned()
|
||||
|
||||
def get_accounts_list(self):
|
||||
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/comptesCommun/synthese_assurancesEtComptes/rechercheContratAssurance-synthese.ea")
|
||||
return self.page.get_accounts_list()
|
||||
|
||||
def get_account(self, id):
|
||||
if not self.is_on_page(AccountList):
|
||||
self.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/comptesCommun/synthese_assurancesEtComptes/rechercheContratAssurance-synthese.ea")
|
||||
return self.page.get_account(id)
|
||||
|
||||
def get_history(self, Account):
|
||||
self.location(Account.link_id)
|
||||
return self.page.get_history()
|
||||
|
||||
def make_transfer(self, from_account, to_account, amount):
|
||||
self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virement/virementSafran_aiguillage/init-saisieComptes.ea')
|
||||
self.page.set_accouts(from_account, to_account)
|
||||
|
||||
#TODO: Check
|
||||
self.page.complete_transfer(amount)
|
||||
|
||||
self.page.confirm()
|
||||
|
||||
id_transfer = self.page.get_transfer_id()
|
||||
transfer = Transfer(id_transfer)
|
||||
transfer.amount = amount
|
||||
transfer.origin = from_account.label
|
||||
transfer.recipient = to_account.label
|
||||
transfer.date = datetime.now()
|
||||
return transfer
|
||||
BIN
modules/bp/favicon.png
Normal file
BIN
modules/bp/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
28
modules/bp/pages/__init__.py
Normal file
28
modules/bp/pages/__init__.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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 .login import LoginPage, Initident, CheckPassword,repositionnerCheminCourant, BadLoginPage, AccountDesactivate
|
||||
from .accountlist import AccountList
|
||||
from .accounthistory import AccountHistory
|
||||
from .transfer import TransferChooseAccounts, CompleteTransfer, TransferConfirm, TransferSummary
|
||||
|
||||
|
||||
__all__ = ['LoginPage','Initident', 'CheckPassword', 'repositionnerCheminCourant', "AccountList", 'AccountHistory', 'BadLoginPage',
|
||||
'AccountDesactivate', 'TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']
|
||||
60
modules/bp/pages/accounthistory.py
Normal file
60
modules/bp/pages/accounthistory.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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 Operation
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
|
||||
__all__ = ['AccountHistory']
|
||||
|
||||
|
||||
class AccountHistory(BasePage):
|
||||
|
||||
def get_history(self):
|
||||
mvt_table = self.document.xpath("//table[@id='mouvements']", smart_strings=False)[0]
|
||||
mvt_ligne = mvt_table.xpath("./tbody/tr")
|
||||
|
||||
operations = []
|
||||
|
||||
for mvt in mvt_ligne:
|
||||
operation = Operation(len(operations))
|
||||
operation.date = mvt.xpath("./td/span")[0].text
|
||||
tmp = mvt.xpath("./td/span")[1]
|
||||
operation.label = unicode(self.parser.tocleanstring(tmp))
|
||||
|
||||
r = re.compile(r'\d+')
|
||||
|
||||
tmp = mvt.xpath("./td/span/strong")
|
||||
if not tmp:
|
||||
tmp = mvt.xpath("./td/span")
|
||||
amount = None
|
||||
for t in tmp:
|
||||
if r.search(t.text):
|
||||
amount = t.text
|
||||
amount = ''.join( amount.replace('.', '').replace(',', '.').split() )
|
||||
if amount[0] == "-":
|
||||
operation.amount = -float(amount[1:])
|
||||
else:
|
||||
operation.amount = float(amount)
|
||||
|
||||
operations.append(operation)
|
||||
return operations
|
||||
69
modules/bp/pages/accountlist.py
Normal file
69
modules/bp/pages/accountlist.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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.capabilities.bank import Account, AccountNotFound
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
|
||||
__all__ = ['AccountList']
|
||||
|
||||
|
||||
class AccountList(BasePage):
|
||||
def on_loaded(self):
|
||||
self.account_list = []
|
||||
self.parse_table('comptes')
|
||||
self.parse_table('comptesEpargne')
|
||||
self.parse_table('comptesTitres')
|
||||
self.parse_table('comptesVie')
|
||||
self.parse_table('comptesRetraireEuros')
|
||||
|
||||
def get_accounts_list(self):
|
||||
return self.account_list
|
||||
|
||||
def parse_table(self, what):
|
||||
tables = self.document.xpath("//table[@id='%s']" % what, smart_strings=False)
|
||||
if len(tables) < 1:
|
||||
return
|
||||
|
||||
lines = tables[0].xpath(".//tbody/tr")
|
||||
for line in lines:
|
||||
account = Account()
|
||||
tmp = line.xpath("./td//a")[0]
|
||||
account.label = tmp.text
|
||||
account.link_id = tmp.get("href")
|
||||
|
||||
tmp = line.xpath("./td//strong")
|
||||
if len(tmp) != 2:
|
||||
tmp_id = line.xpath("./td//span")[1].text
|
||||
tmp_balance = tmp[0].text
|
||||
else:
|
||||
tmp_id = tmp[0].text
|
||||
tmp_balance = tmp[1].text
|
||||
|
||||
account.id = tmp_id
|
||||
account.balance = float(''.join(tmp_balance.replace('.','').replace(',','.').split()))
|
||||
self.account_list.append(account)
|
||||
|
||||
def get_account(self, id):
|
||||
for account in self.account_list:
|
||||
if account.id == id:
|
||||
return account
|
||||
raise AccountNotFound('Unable to find account: %s' % id)
|
||||
74
modules/bp/pages/login.py
Normal file
74
modules/bp/pages/login.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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 hashlib
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
|
||||
__all__ = ['LoginPage', 'BadLoginPage', 'AccountDesactivate', 'Initident', 'CheckPassword', 'repositionnerCheminCourant']
|
||||
|
||||
|
||||
def md5(f):
|
||||
md5 = hashlib.md5()
|
||||
md5.update(f.read())
|
||||
return md5.hexdigest()
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def on_loaded(self):
|
||||
pass
|
||||
|
||||
def login(self, login, pwd):
|
||||
LOCAL_HASH = ['a02574d7bf67677d2a86b7bfc5e864fe', 'eb85e1cc45dd6bdb3cab65c002d7ac8a',
|
||||
'596e6fbd54d5b111fe5df8a4948e80a4', '9cdc989a4310554e7f5484d0d27a86ce',
|
||||
'0183943de6c0e331f3b9fc49c704ac6d', '291b9987225193ab1347301b241e2187',
|
||||
'163279f1a46082408613d12394e4042a', 'b0a9c740c4cada01eb691b4acda4daea',
|
||||
'3c4307ee92a1f3b571a3c542eafcb330', 'dbccecfa2206bfdb4ca891476404cc68']
|
||||
|
||||
process = lambda i: md5(self.browser.openurl(('https://voscomptesenligne.labanquepostale.fr/wsost/OstBrokerWeb/loginform?imgid=%d&0.25122230781963073' % i)))
|
||||
keypad = [process(i) for i in range(10)]
|
||||
correspondance = [keypad.index(i) for i in LOCAL_HASH]
|
||||
newpassword = ''.join(str(correspondance[int(c)]) for c in pwd)
|
||||
|
||||
self.browser.select_form(name='formAccesCompte')
|
||||
self.browser.set_all_readonly(False)
|
||||
self.browser['password'] = newpassword
|
||||
self.browser['username'] = login
|
||||
self.browser.submit()
|
||||
|
||||
class repositionnerCheminCourant(BasePage):
|
||||
def on_loaded(self):
|
||||
self.browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/securite/authentification/initialiser-identif.ea")
|
||||
|
||||
class Initident(BasePage):
|
||||
def on_loaded(self):
|
||||
self.browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/securite/authentification/verifierMotDePasse-identif.ea")
|
||||
|
||||
class CheckPassword(BasePage):
|
||||
def on_loaded(self):
|
||||
self.browser.open("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/comptesCommun/synthese_assurancesEtComptes/init-synthese.ea")
|
||||
|
||||
|
||||
class BadLoginPage(BasePage):
|
||||
pass
|
||||
|
||||
|
||||
class AccountDesactivate(BasePage):
|
||||
pass
|
||||
74
modules/bp/pages/transfer.py
Normal file
74
modules/bp/pages/transfer.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Nicolas Duhamel
|
||||
#
|
||||
# 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 TransferError
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.tools.misc import to_unicode
|
||||
|
||||
|
||||
__all__ = ['TransferChooseAccounts', 'CompleteTransfer', 'TransferConfirm', 'TransferSummary']
|
||||
|
||||
|
||||
class TransferChooseAccounts(BasePage):
|
||||
def set_accouts(self, from_account, to_account):
|
||||
self.browser.select_form(name="AiguillageForm")
|
||||
self.browser["idxCompteEmetteur"] = [from_account.id]
|
||||
self.browser["idxCompteReceveur"] = [to_account.id]
|
||||
self.browser.submit()
|
||||
|
||||
|
||||
class CompleteTransfer(BasePage):
|
||||
def complete_transfer(self, amount):
|
||||
self.browser.select_form(name="virement_unitaire_saisie_saisie_virement_sepa")
|
||||
self.browser["montant"] = str(amount)
|
||||
self.browser.submit()
|
||||
|
||||
|
||||
class TransferConfirm(BasePage):
|
||||
def confirm(self):
|
||||
self.browser.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virement/virementSafran_national/confirmerVirementNational-virementNational.ea')
|
||||
|
||||
|
||||
class TransferSummary(BasePage):
|
||||
def get_transfer_id(self):
|
||||
p = self.document.xpath("//div[@id='main']/div/p")[0]
|
||||
|
||||
#HACK for deal with bad encoding ...
|
||||
try:
|
||||
text = p.text
|
||||
except UnicodeDecodeError, error:
|
||||
text = error.object.strip()
|
||||
|
||||
match = re.search("Votre virement N.+ ([0-9]+) ", text)
|
||||
if match:
|
||||
id_transfer = match.groups()[0]
|
||||
return id_transfer
|
||||
|
||||
if text.startswith(u"Votre virement n'a pas pu"):
|
||||
if p.find('br') is not None:
|
||||
errmsg = to_unicode(p.find('br').tail).strip()
|
||||
raise TransferError('Unable to process transfer: %s' % errmsg)
|
||||
else:
|
||||
self.browser.logger.warning('Unable to find the error reason')
|
||||
|
||||
self.browser.logger.error('Unable to parse the text result: %r' % text)
|
||||
raise TransferError('Unable to process transfer: %r' % text)
|
||||
Loading…
Add table
Add a link
Reference in a new issue