support both pro and perso websites
This commit is contained in:
parent
1b09042b67
commit
b0fd66ae67
7 changed files with 292 additions and 8 deletions
0
modules/creditcooperatif/perso/__init__.py
Normal file
0
modules/creditcooperatif/perso/__init__.py
Normal file
110
modules/creditcooperatif/perso/browser.py
Normal file
110
modules/creditcooperatif/perso/browser.py
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Kevin Pouget
|
||||
#
|
||||
# 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 urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
|
||||
from .pages import LoginPage, LoggedPage, AccountsPage, TransactionsPage, TransactionsJSONPage, ComingTransactionsPage
|
||||
|
||||
|
||||
__all__ = ['CreditCooperatif']
|
||||
|
||||
|
||||
class CreditCooperatif(BaseBrowser):
|
||||
PROTOCOL = 'https'
|
||||
ENCODING = 'iso-8859-15'
|
||||
DOMAIN = "www.credit-cooperatif.coop"
|
||||
PAGES = {'https://www.credit-cooperatif.coop/portail/particuliers/login.do': LoginPage,
|
||||
'https://www.credit-cooperatif.coop/portail/particuliers/authentification.do': LoggedPage,
|
||||
'https://www.credit-cooperatif.coop/portail/particuliers/mescomptes/synthese.do': AccountsPage,
|
||||
'https://www.credit-cooperatif.coop/portail/particuliers/mescomptes/relevedesoperations.do': TransactionsPage,
|
||||
'https://www.credit-cooperatif.coop/portail/particuliers/mescomptes/relevedesoperationsjson.do': (TransactionsJSONPage, 'json'),
|
||||
'https://www.credit-cooperatif.coop/portail/particuliers/mescomptes/synthese/operationsencourslien.do': ComingTransactionsPage,
|
||||
}
|
||||
|
||||
def home(self):
|
||||
self.location("/portail/particuliers/mescomptes/synthese.do")
|
||||
|
||||
def is_logged(self):
|
||||
return not self.is_on_page(LoginPage)
|
||||
|
||||
def login(self):
|
||||
"""
|
||||
Attempt to log in.
|
||||
Note: this method does nothing if we are already logged in.
|
||||
"""
|
||||
|
||||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
|
||||
if self.is_logged():
|
||||
return
|
||||
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.home()
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
|
||||
if self.is_on_page(LoggedPage):
|
||||
error = self.page.get_error()
|
||||
if error is not None:
|
||||
raise BrowserIncorrectPassword(error)
|
||||
|
||||
if not self.is_logged():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
def get_accounts_list(self):
|
||||
if not self.is_on_page(AccountsPage):
|
||||
self.location('/portail/particuliers/mescomptes/synthese.do')
|
||||
|
||||
return self.page.get_list()
|
||||
|
||||
def get_account(self, id):
|
||||
assert isinstance(id, basestring)
|
||||
|
||||
for a in self.get_accounts_list():
|
||||
if a.id == id:
|
||||
return a
|
||||
|
||||
return None
|
||||
|
||||
def get_history(self, account):
|
||||
data = {'accountExternalNumber': account.id}
|
||||
self.location('/portail/particuliers/mescomptes/relevedesoperations.do', urllib.urlencode(data))
|
||||
|
||||
data = {'iDisplayLength': 400,
|
||||
'iDisplayStart': 0,
|
||||
'iSortCol_0': 0,
|
||||
'iSortingCols': 1,
|
||||
'sColumns': '',
|
||||
'sEcho': 1,
|
||||
'sSortDir_0': 'asc',
|
||||
}
|
||||
self.location('/portail/particuliers/mescomptes/relevedesoperationsjson.do', urllib.urlencode(data))
|
||||
|
||||
return self.page.get_transactions()
|
||||
|
||||
def get_coming(self, account):
|
||||
data = {'accountExternalNumber': account.id}
|
||||
self.location('/portail/particuliers/mescomptes/synthese/operationsencourslien.do', urllib.urlencode(data))
|
||||
|
||||
assert self.is_on_page(ComingTransactionsPage)
|
||||
|
||||
return self.page.get_transactions()
|
||||
134
modules/creditcooperatif/perso/pages.py
Normal file
134
modules/creditcooperatif/perso/pages.py
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Kevin Pouget
|
||||
#
|
||||
# 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 decimal import Decimal
|
||||
import re
|
||||
|
||||
from weboob.tools.json import json
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||
|
||||
|
||||
__all__ = ['LoginPage', 'AccountsPage', 'TransactionsPage', 'ComingTransactionsPage']
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def login(self, login, password):
|
||||
self.browser.select_form(predicate=lambda form: form.attrs.get('id', '') == 'AuthForm')
|
||||
self.browser['j_username'] = login.encode('iso-8859-15')
|
||||
self.browser['j_password'] = password.encode('iso-8859-15')
|
||||
self.browser.submit(nologin=True)
|
||||
|
||||
class LoggedPage(BasePage):
|
||||
def get_error(self):
|
||||
div = self.document.xpath('//div[@class="errorForm-msg"]')
|
||||
if len(div) == 0:
|
||||
return None
|
||||
|
||||
msg = u', '.join([li.text.strip() for li in div[0].xpath('.//li')])
|
||||
return re.sub('[\r\n\t\xa0]+', ' ', msg)
|
||||
|
||||
class AccountsPage(BasePage):
|
||||
ACCOUNT_TYPES = {u'COMPTE NEF': Account.TYPE_CHECKING}
|
||||
|
||||
def get_list(self):
|
||||
for table in self.document.getroot().cssselect('table.table-synthese'):
|
||||
account = Account()
|
||||
labels = table.xpath('.//ul[@class="nClient"]/li')
|
||||
account_type_str = table.xpath('.//h2[@class="tt_compte"]')[0].text.strip()
|
||||
|
||||
account.id = re.sub(u'[^0-9]', '', labels[-1].text)
|
||||
account.label = u' '.join([account_type_str, labels[0].text.strip()])
|
||||
account.type = self.ACCOUNT_TYPES.get(account_type_str, Account.TYPE_UNKNOWN)
|
||||
|
||||
balance = table.xpath('.//td[@class="sum_solde"]//span')[-1].text
|
||||
account.balance = Decimal(FrenchTransaction.clean_amount(balance))
|
||||
account.currency = account.get_currency(balance)
|
||||
|
||||
yield account
|
||||
|
||||
class Transaction(FrenchTransaction):
|
||||
PATTERNS = [(re.compile('^(?P<text>RETRAIT DAB) (?P<dd>\d{2})-(?P<mm>\d{2})-([\d\-]+)'),
|
||||
FrenchTransaction.TYPE_WITHDRAWAL),
|
||||
(re.compile('^RETRAIT DAB (?P<dd>\d{2})-(?P<mm>\d{2})-([\d\-]+) (?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_WITHDRAWAL),
|
||||
(re.compile('^CARTE (?P<dd>\d{2})(?P<mm>\d{2}) \d+ (?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_CARD),
|
||||
(re.compile('^VIR COOPA (?P<dd>\d{2})/(?P<mm>\d{2}) (?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_TRANSFER),
|
||||
(re.compile('^VIR(EMENT|EMT)? (?P<text>.*?)(- .*)?$'),
|
||||
FrenchTransaction.TYPE_TRANSFER),
|
||||
(re.compile('^(PRLV|PRELEVEMENT) (?P<text>.*?)(- .*)?$'),
|
||||
FrenchTransaction.TYPE_ORDER),
|
||||
(re.compile('^CHEQUE.*'), FrenchTransaction.TYPE_CHECK),
|
||||
(re.compile('^(AGIOS /|FRAIS) (?P<text>.*)'),FrenchTransaction.TYPE_BANK),
|
||||
(re.compile('^ABONNEMENT (?P<text>.*)'), FrenchTransaction.TYPE_BANK),
|
||||
(re.compile('^REMISE (?P<text>.*)'), FrenchTransaction.TYPE_DEPOSIT),
|
||||
(re.compile('^(?P<text>.*)( \d+)? QUITTANCE .*'),
|
||||
FrenchTransaction.TYPE_ORDER),
|
||||
(re.compile('^.* LE (?P<dd>\d{2})/(?P<mm>\d{2})/(?P<yy>\d{2})$'),
|
||||
FrenchTransaction.TYPE_UNKNOWN),
|
||||
]
|
||||
|
||||
class TransactionsPage(BasePage):
|
||||
pass
|
||||
|
||||
class TransactionsJSONPage(BasePage):
|
||||
ROW_DATE = 0
|
||||
ROW_TEXT = 2
|
||||
ROW_CREDIT = -1
|
||||
ROW_DEBIT = -2
|
||||
|
||||
def get_transactions(self):
|
||||
for tr in self.document['exportData'][1:]:
|
||||
t = Transaction(0)
|
||||
t.parse(tr[self.ROW_DATE], tr[self.ROW_TEXT])
|
||||
t.set_amount(tr[self.ROW_CREDIT], tr[self.ROW_DEBIT])
|
||||
yield t
|
||||
|
||||
class ComingTransactionsPage(BasePage):
|
||||
ROW_REF = 0
|
||||
ROW_TEXT = 1
|
||||
ROW_DATE = 2
|
||||
ROW_CREDIT = -1
|
||||
ROW_DEBIT = -2
|
||||
|
||||
def get_transactions(self):
|
||||
data = []
|
||||
for script in self.document.xpath('//script'):
|
||||
txt = script.text
|
||||
if txt is None:
|
||||
continue
|
||||
|
||||
pattern = 'var jsonData ='
|
||||
start = txt.find(pattern)
|
||||
if start < 0:
|
||||
continue
|
||||
|
||||
txt = txt[start+len(pattern):start+txt[start:].find(';')]
|
||||
data = json.loads(txt)
|
||||
break
|
||||
|
||||
for tr in data:
|
||||
t = Transaction(0)
|
||||
t.parse(tr[self.ROW_DATE], tr[self.ROW_TEXT])
|
||||
t.set_amount(tr[self.ROW_CREDIT], tr[self.ROW_DEBIT])
|
||||
yield t
|
||||
Loading…
Add table
Add a link
Reference in a new issue