handle transfer errors
This commit is contained in:
parent
23f6a60521
commit
fe85423051
1 changed files with 17 additions and 14 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
from weboob.capabilities.bank import TransferError
|
from weboob.capabilities.bank import TransferError
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
|
from weboob.tools.misc import to_unicode
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
@ -46,20 +47,22 @@ class TransferConfirm(BasePage):
|
||||||
self.browser.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")
|
self.browser.location("https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virementsafran/virementnational/4-virementNational.ea")
|
||||||
|
|
||||||
class TransferSummary(BasePage):
|
class TransferSummary(BasePage):
|
||||||
|
OK_PATTERN = re.compile("Votre virement N.+ ([0-9]+) ")
|
||||||
|
ERROR_PATTERN = re.compile('Votre virement n\'a pas pu')
|
||||||
|
|
||||||
def get_transfer_id(self):
|
def get_transfer_id(self):
|
||||||
pattern = "Votre virement N.+ ([0-9]+) "
|
p = self.document.xpath("//form/div/p")[0]
|
||||||
regex = re.compile(pattern)
|
text = to_unicode(p.text)
|
||||||
#HACK for deal with bad encoding ...
|
|
||||||
try:
|
|
||||||
text = self.document.xpath("//form/div/p")[0].text
|
|
||||||
except UnicodeDecodeError, error:
|
|
||||||
text = error.object
|
|
||||||
match = regex.search(text)
|
|
||||||
if not match:
|
|
||||||
self.browser.logger.error('Unable to parse the text result: %r' % text)
|
|
||||||
raise TransferError('Unable to process transfer: %r' % text)
|
|
||||||
|
|
||||||
id_transfer = match.groups()[0]
|
match = self.OK_PATTERN.search(text)
|
||||||
return id_transfer
|
if match:
|
||||||
|
id_transfer = match.groups()[0]
|
||||||
|
return id_transfer
|
||||||
|
|
||||||
|
match = self.ERROR_PATTERN.search(text)
|
||||||
|
if match and p.find('br'):
|
||||||
|
errmsg = to_unicode(p.find('br').tail).strip()
|
||||||
|
raise TransferError('Unable to process transfer: %s' % errmsg)
|
||||||
|
|
||||||
|
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