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/creditmutuel/__init__.py
Normal file
23
modules/creditmutuel/__init__.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Julien Veyssier
|
||||
#
|
||||
# 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 CreditMutuelBackend
|
||||
|
||||
__all__ = ['CreditMutuelBackend']
|
||||
64
modules/creditmutuel/backend.py
Normal file
64
modules/creditmutuel/backend.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Julien Veyssier
|
||||
#
|
||||
# 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 CreditMutuelBrowser
|
||||
|
||||
|
||||
__all__ = ['CreditMutuelBackend']
|
||||
|
||||
|
||||
class CreditMutuelBackend(BaseBackend, ICapBank):
|
||||
NAME = 'creditmutuel'
|
||||
MAINTAINER = 'Julien Veyssier'
|
||||
EMAIL = 'julien.veyssier@aiur.fr'
|
||||
VERSION = '0.a'
|
||||
DESCRIPTION = u'Crédit Mutuel french bank'
|
||||
LICENSE = 'AGPLv3+'
|
||||
CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', regexp='^\d{1,13}\w$', masked=False),
|
||||
ValueBackendPassword('password', label='Password of account'))
|
||||
BROWSER = CreditMutuelBrowser
|
||||
|
||||
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):
|
||||
if not _id.isdigit():
|
||||
raise AccountNotFound()
|
||||
account = self.browser.get_account(_id)
|
||||
if account:
|
||||
return account
|
||||
else:
|
||||
raise AccountNotFound()
|
||||
|
||||
def iter_operations(self, account):
|
||||
""" TODO Not supported yet """
|
||||
return iter([])
|
||||
|
||||
def iter_history(self, account):
|
||||
for history in self.browser.get_history(account):
|
||||
yield history
|
||||
117
modules/creditmutuel/browser.py
Normal file
117
modules/creditmutuel/browser.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Julien Veyssier
|
||||
#
|
||||
# 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.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
|
||||
from .pages import LoginPage, LoginErrorPage, AccountsPage, OperationsPage, InfoPage
|
||||
|
||||
__all__ = ['CreditMutuelBrowser']
|
||||
|
||||
# Browser
|
||||
class CreditMutuelBrowser(BaseBrowser):
|
||||
PROTOCOL = 'https'
|
||||
DOMAIN = 'www.creditmutuel.fr'
|
||||
ENCODING = 'iso-8859-1'
|
||||
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
||||
PAGES = {'https://www.creditmutuel.fr/groupe/fr/index.html': LoginPage,
|
||||
'https://www.creditmutuel.fr/groupe/fr/identification/default.cgi': LoginErrorPage,
|
||||
'https://www.creditmutuel.fr/.*/fr/banque/situation_financiere.cgi': AccountsPage,
|
||||
'https://www.creditmutuel.fr/.*/fr/banque/mouvements.cgi.*' : OperationsPage,
|
||||
'https://www.creditmutuel.fr/.*/fr/banque/BAD.*' : InfoPage
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
#self.SUB_BANKS = ['cmdv','cmcee','cmse', 'cmidf', 'cmsmb', 'cmma', 'cmmabn', 'cmc', 'cmlaco', 'cmnormandie', 'cmm']
|
||||
#self.currentSubBank = None
|
||||
|
||||
def is_logged(self):
|
||||
return self.page and not self.is_on_page(LoginPage)
|
||||
|
||||
def home(self):
|
||||
return self.location('https://www.creditmutuel.fr/groupe/fr/index.html')
|
||||
|
||||
|
||||
def login(self):
|
||||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.location('https://www.creditmutuel.fr/', no_login=True)
|
||||
|
||||
self.page.login( self.username, self.password)
|
||||
|
||||
if not self.is_logged() or self.is_on_page(LoginErrorPage):
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
self.SUB_BANKS = ['cmdv','cmcee','cmse', 'cmidf', 'cmsmb', 'cmma', 'cmmabn', 'cmc', 'cmlaco', 'cmnormandie', 'cmm']
|
||||
self.getCurrentSubBank()
|
||||
|
||||
def get_accounts_list(self):
|
||||
if not self.is_on_page(AccountsPage):
|
||||
self.location('https://www.creditmutuel.fr/%s/fr/banque/situation_financiere.cgi'%self.currentSubBank)
|
||||
return self.page.get_list()
|
||||
|
||||
def get_account(self, id):
|
||||
assert isinstance(id, basestring)
|
||||
|
||||
l = self.get_accounts_list()
|
||||
for a in l:
|
||||
if a.id == id:
|
||||
return a
|
||||
|
||||
return None
|
||||
|
||||
def getCurrentSubBank(self):
|
||||
# the account list and history urls depend on the sub bank of the user
|
||||
current_url = self.geturl()
|
||||
current_url_parts = current_url.split('/')
|
||||
for subbank in self.SUB_BANKS:
|
||||
if subbank in current_url_parts:
|
||||
self.currentSubBank = subbank
|
||||
|
||||
def get_history(self, account):
|
||||
page_url = account.link_id
|
||||
#operations_count = 0
|
||||
l_ret = []
|
||||
while (page_url):
|
||||
self.location('https://%s/%s/fr/banque/%s' % (self.DOMAIN, self.currentSubBank, page_url))
|
||||
#for page_operation in self.page.get_history(operations_count):
|
||||
# operations_count += 1
|
||||
# yield page_operation
|
||||
|
||||
## FONCTIONNE
|
||||
#for op in self.page.get_history():
|
||||
# yield op
|
||||
|
||||
## FONTIONNE
|
||||
#return self.page.get_history()
|
||||
|
||||
for op in self.page.get_history():
|
||||
l_ret.append(op)
|
||||
page_url = self.page.next_page_url()
|
||||
|
||||
return l_ret
|
||||
|
||||
|
||||
#def get_coming_operations(self, account):
|
||||
# if not self.is_on_page(AccountComing) or self.page.account.id != account.id:
|
||||
# self.location('/NS_AVEEC?ch4=%s' % account.link_id)
|
||||
# return self.page.get_operations()
|
||||
BIN
modules/creditmutuel/favicon.png
Normal file
BIN
modules/creditmutuel/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
95
modules/creditmutuel/pages.py
Normal file
95
modules/creditmutuel/pages.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Julien Veyssier
|
||||
#
|
||||
# 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.browser import BasePage
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.capabilities.bank import Operation
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def login(self, login, passwd):
|
||||
self.browser.select_form(nr=0)
|
||||
self.browser['_cm_user'] = login
|
||||
self.browser['_cm_pwd'] = passwd
|
||||
self.browser.submit()
|
||||
|
||||
class LoginErrorPage(BasePage):
|
||||
pass
|
||||
|
||||
class InfoPage(BasePage):
|
||||
pass
|
||||
|
||||
class AccountsPage(BasePage):
|
||||
def get_list(self):
|
||||
l = []
|
||||
|
||||
for tr in self.document.getiterator('tr'):
|
||||
first_td = tr.getchildren()[0]
|
||||
if first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g':
|
||||
account = Account()
|
||||
account.label = u"%s"%first_td.find('a').text
|
||||
account.link_id = first_td.find('a').get('href', '')
|
||||
account.id = first_td.find('a').text.split(' ')[0]+first_td.find('a').text.split(' ')[1]
|
||||
s = tr.getchildren()[2].text
|
||||
if s.strip() == "":
|
||||
s = tr.getchildren()[1].text
|
||||
balance = u''
|
||||
for c in s:
|
||||
if c.isdigit() or c == '-':
|
||||
balance += c
|
||||
if c == ',':
|
||||
balance += '.'
|
||||
account.balance = float(balance)
|
||||
l.append(account)
|
||||
#raise NotImplementedError()
|
||||
return l
|
||||
|
||||
def next_page_url(self):
|
||||
""" TODO pouvoir passer à la page des comptes suivante """
|
||||
return 0
|
||||
|
||||
class OperationsPage(BasePage):
|
||||
def get_history(self):
|
||||
index = 0
|
||||
for tr in self.document.getiterator('tr'):
|
||||
first_td = tr.getchildren()[0]
|
||||
if first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g':
|
||||
operation = Operation(index)
|
||||
index += 1
|
||||
operation.date = first_td.text
|
||||
operation.label = u"%s"%tr.getchildren()[2].text.replace('\n',' ')
|
||||
if len(tr.getchildren()[3].text) > 2:
|
||||
s = tr.getchildren()[3].text
|
||||
elif len(tr.getchildren()[4].text) > 2:
|
||||
s = tr.getchildren()[4].text
|
||||
else:
|
||||
s = "0"
|
||||
balance = u''
|
||||
for c in s:
|
||||
if c.isdigit() or c == "-":
|
||||
balance += c
|
||||
if c == ',':
|
||||
balance += '.'
|
||||
operation.amount = float(balance)
|
||||
yield operation
|
||||
|
||||
def next_page_url(self):
|
||||
""" TODO pouvoir passer à la page des opérations suivantes """
|
||||
return 0
|
||||
|
||||
27
modules/creditmutuel/test.py
Normal file
27
modules/creditmutuel/test.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Julien Veyssier
|
||||
#
|
||||
# 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 CreditMutuelTest(BackendTest):
|
||||
BACKEND = 'crmut'
|
||||
|
||||
def test_crmut(self):
|
||||
list(self.backend.iter_accounts())
|
||||
Loading…
Add table
Add a link
Reference in a new issue