78 lines
3 KiB
Python
78 lines
3 KiB
Python
# -*- 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
|