pax_global_header 0000666 0000000 0000000 00000000064 14042356110 0014506 g ustar 00root root 0000000 0000000 52 comment=18d41565f955028f9fcd2f6cc437f5f1cb717401
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/ 0000775 0000000 0000000 00000000000 14042356110 0023464 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/ 0000775 0000000 0000000 00000000000 14042356110 0025134 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/themisbanque/ 0000775 0000000 0000000 00000000000 14042356110 0027621 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/themisbanque/__init__.py 0000664 0000000 0000000 00000001503 14042356110 0031731 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2015 Romain Bignon
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from .module import ThemisModule
__all__ = ['ThemisModule']
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/themisbanque/browser.py 0000664 0000000 0000000 00000006515 14042356110 0031665 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2015 Romain Bignon
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from woob.browser import LoginBrowser, URL, need_login
from woob.tools.compat import urljoin
from .pages import LoginPage, LoginConfirmPage, AccountsPage, RibPage, RibPDFPage, HistoryPage
class ThemisBrowser(LoginBrowser):
BASEURL = 'https://esab.themisbanque.eu/'
TIMEOUT = 90
home = URL(r'/es@b/fr/esab.jsp')
login = URL(r'/es@b/fr/codeident.jsp', LoginPage)
login_confirm = URL(r'/es@b/servlet/internet0.ressourceWeb.servlet.Login', LoginConfirmPage)
accounts = URL(r'/es@b/servlet/internet0.ressourceWeb.servlet.PremierePageServlet\?pageToTreatError=fr/Infos.jsp&dummyDate=',
r'/es@b/servlet/internet0.ressourceWeb.servlet.PremierePageServlet\?cryptpara=.*',
r'/es@b/servlet/internet0.ressourceWeb.servlet.EsabServlet.*',
AccountsPage)
history = URL(r'/es@b/servlet/internet0.ressourceWeb.servlet.ListeDesMouvementsServlet.*', HistoryPage)
rib = URL(r'/es@b/fr/rib.jsp\?cryptpara=.*', RibPage)
rib_pdf = URL(r'/es@b/servlet/internet0.ressourceWeb.servlet.RibPdfDownloadServlet', RibPDFPage)
def do_login(self):
self.home.go()
self.login.go()
self.page.login(self.username, self.password)
@need_login
def iter_accounts(self):
self.accounts.stay_or_go()
# sometimes when the user has messages, accounts's page will redirect
# to the message page and the user will have to click "ok" to access his accounts
# this will happen as long as the messages aren't deleted.
# In this case, accounts may be reached through a different link (in the "ok" button)
acc_link = self.page.get_acc_link()
if acc_link:
self.location(urljoin(self.BASEURL, acc_link))
return self.page.iter_accounts()
@need_login
def get_history(self, account):
if account._link:
self.location(account._link)
for tr in self._dedup_transactions(self.page.get_operations()):
yield tr
@staticmethod
def _dedup_transactions(transactions):
# Sometime the website returns the same list of transactions for each history page.
# So we process the transactions list, and stop if any transaction is newer than the previous one.
last_date = None
for i, tr in enumerate(transactions):
if last_date and tr.date > last_date:
break
last_date = tr.date
yield tr
@need_login
def get_profile(self):
accounts = list(self.iter_accounts())
self.location(accounts[0]._url)
return self.page.get_profile()
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/themisbanque/module.py 0000664 0000000 0000000 00000004261 14042356110 0031463 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2015 Romain Bignon
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
from woob.tools.backend import Module, BackendConfig
from woob.capabilities.bank import CapBank, AccountNotFound
from woob.capabilities.base import find_object
from woob.capabilities.profile import CapProfile
from woob.tools.value import ValueBackendPassword
from .browser import ThemisBrowser
__all__ = ['ThemisModule']
class ThemisModule(Module, CapBank, CapProfile):
NAME = 'themisbanque'
DESCRIPTION = 'Themis'
MAINTAINER = 'Romain Bignon'
EMAIL = 'romain@weboob.org'
LICENSE = 'LGPLv3+'
VERSION = '3.1'
CONFIG = BackendConfig(
ValueBackendPassword('login', label="Numéro d'abonné", masked=False),
ValueBackendPassword('password', label='Code secret'),
)
BROWSER = ThemisBrowser
def create_default_browser(self):
return self.create_browser(self.config['login'].get(),
self.config['password'].get())
def get_account(self, _id):
return find_object(self.browser.iter_accounts(), id=_id, error=AccountNotFound)
def iter_accounts(self):
return self.browser.iter_accounts()
def iter_coming(self, account):
raise NotImplementedError()
def iter_history(self, account):
return self.browser.get_history(account)
def iter_investment(self, account):
raise NotImplementedError()
def get_profile(self):
return self.browser.get_profile()
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/themisbanque/pages.py 0000664 0000000 0000000 00000027237 14042356110 0031305 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2015 Romain Bignon
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
import re
from woob.exceptions import BrowserIncorrectPassword
from woob.browser.pages import LoggedPage, HTMLPage, pagination, PDFPage
from woob.browser.elements import method, ItemElement, TableElement
from woob.capabilities.bank import Account
from woob.capabilities.base import NotAvailable
from woob.capabilities.profile import Profile
from woob.browser.filters.standard import CleanText, CleanDecimal, Async, Regexp, Join, Field
from woob.browser.filters.html import Link, TableCell, ColumnNotFound
from woob.tools.capabilities.bank.transactions import FrenchTransaction
from woob.tools.capabilities.bank.iban import is_iban_valid
from woob.tools.compat import basestring
from woob.tools.pdf import extract_text
class MyCleanText(CleanText):
@classmethod
def clean(cls, txt, children=True, newlines=True, transliterate=False, normalize='NFC', **kwargs):
if not isinstance(txt, basestring):
txt = '\n'.join([t.strip() for t in txt.itertext()])
return txt
class LoginPage(HTMLPage):
def login(self, username, password):
form = self.get_form()
form['identifiant'] = username
form['motpasse'] = password
form.submit()
class LoginConfirmPage(HTMLPage):
def on_load(self):
error = CleanText('//td[has-class("ColonneLibelle")]')(self.doc)
if len(error) > 0:
raise BrowserIncorrectPassword(error)
class AccountsPage(LoggedPage, HTMLPage):
def get_acc_link(self):
msg = CleanText('//body[@class="message"]')(self.doc)
if msg:
acc_link = Link('//div[@class="Boutons"]/a', 'href')(self.doc)
return acc_link
@method
class iter_accounts(TableElement):
item_xpath = '//table[has-class("TableBicolore")]//tr[@id and count(td) > 4]'
head_xpath = '//table[has-class("TableBicolore")]//tr/td[@id]/@id'
col_id = 'idCompteLibelle'
col_label = 'idCompteIntitule'
col_balance = 'idCompteSolde'
col_currency = 'idCompteSoldeUM'
col_rib = 'idCompteRIB'
col_type = 'idCompteNature'
class item(ItemElement):
klass = Account
def condition(self):
return CleanDecimal(TableCell('balance'), replace_dots=True, default=NotAvailable)(self) is not NotAvailable
TYPE = {
'COMPTE COURANT': Account.TYPE_CHECKING,
'COMPTE TRANSACTION': Account.TYPE_CHECKING,
'COMPTE ORDINAIRE': Account.TYPE_CHECKING,
}
TYPE_BY_LABELS = {
'CAV': Account.TYPE_CHECKING,
}
obj_id = CleanText(TableCell('id'))
obj_label = CleanText(TableCell('label'))
obj_currency = FrenchTransaction.Currency(TableCell('currency'))
obj_balance = CleanDecimal(TableCell('balance'), replace_dots=True)
def obj__link(self):
return Link(TableCell('id')(self)[0].xpath('./a'), default=None)(self)
def obj__url(self):
return Link(TableCell('rib')(self)[0].xpath('./a[img[starts-with(@alt, "RIB")]]'), default=None)(self)
def load_iban(self):
link = Link(TableCell('rib')(self)[0].xpath('./a[img[starts-with(@alt, "RIB")]]'), default=None)(self)
return self.page.browser.async_open(link)
def obj_type(self):
try:
el_to_check = CleanText(TableCell('type'))(self)
type_dict = self.TYPE
except ColumnNotFound:
el_to_check = Field('label')(self)
type_dict = self.TYPE_BY_LABELS
for k, v in type_dict.items():
if el_to_check.startswith(k):
return v
return Account.TYPE_UNKNOWN
def obj_iban(self):
rib_page = Async('iban').loaded_page(self)
if 'RibPdf' in rib_page.url:
return rib_page.get_iban()
return Join('', Regexp(CleanText('//td[has-class("ColonneCode")][contains(text(), "IBAN")]'), r'\b((?!IBAN)[A-Z0-9]+)\b', nth='*'))(rib_page.doc) or NotAvailable
class RibPage(LoggedPage, HTMLPage):
def get_profile(self):
profile = Profile()
# profile is inside a
separated with a simple without or
profile_txt = MyCleanText('//div[@class="TableauAffichage"]/table/tr[3]/td[1]')(self.doc).split('\n')
i_name = 0
profile.name = ''
# name can be on one, two, (more ?) lines, so we stop when line start by a number, we suppose it's the address number
while not re.search(r'^\d', profile_txt[i_name]):
profile.name += ' ' + profile_txt[i_name]
i_name += 1
profile.name = profile.name.strip()
profile.address = ''
# address is not always on two lines, so we consider every lines from here to before last are address, (last one is country)
for i in range(i_name, len(profile_txt)-1):
profile.address += ' ' + profile_txt[i]
profile.address = profile.address.strip()
profile.country = profile_txt[-1]
profile.name = profile.name.replace('MONSIEUR ', '').replace('MADAME ', '')
return profile
class RibPDFPage(LoggedPage, PDFPage):
def get_iban(self):
text = extract_text(self.content)
iban = re.search(r'IBAN([A-Z]{2}\d+)', text).group(1)
assert is_iban_valid(iban), 'did not parse IBAN properly'
return iban
class Transaction(FrenchTransaction):
PATTERNS = [
(re.compile(r'^VIR(EMENT)?( SEPA)? (?P.*)'), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r'^PRLV (?P.*)'), FrenchTransaction.TYPE_ORDER),
(re.compile(r'^(?P.*) CARTE \d+ PAIEMENT CB\s+(?P\d{2})(?P\d{2}) ?(.*)$'), FrenchTransaction.TYPE_CARD),
(re.compile(r'^RETRAIT DAB (?P\d{2})(?P\d{2}) (?P.*) CARTE [\*\d]+'), FrenchTransaction.TYPE_WITHDRAWAL),
(re.compile(r'^CHEQUE( (?P.*))?$'), FrenchTransaction.TYPE_CHECK),
(re.compile(r'^(F )?COTIS\.? (?P.*)'), FrenchTransaction.TYPE_BANK),
(re.compile(r'^(REMISE|REM.CHQ) (?P.*)'), FrenchTransaction.TYPE_DEPOSIT),
(re.compile(r'^(?P.*)(?P\d{2})(?P\d{2}) CARTE BLEUE'), FrenchTransaction.TYPE_CARD),
(re.compile(r'^PRVL SEPA (?P.*)'), FrenchTransaction.TYPE_ORDER),
(re.compile(r'^(?P(INT. DEBITEURS).*)'), FrenchTransaction.TYPE_BANK),
(re.compile(r'^(?P.*(VIR EMIS).*)'), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r'^(?P.*(\bMOUVEMENT\b).*)'), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r'^(?P.*(ARRETE TRIM.).*)'), FrenchTransaction.TYPE_BANK),
(re.compile(r'^(?P.*(TENUE DE DOSSIE).*)'), FrenchTransaction.TYPE_BANK),
(re.compile(r'^(?P.*(RELEVE LCR ECH).*)'), FrenchTransaction.TYPE_ORDER),
(re.compile(r'^(?P.*(\+ FORT DECOUVERT).*)'), FrenchTransaction.TYPE_BANK),
(re.compile(r'^(?P.*(EXTRANET @THEMI).*)'), FrenchTransaction.TYPE_BANK),
(re.compile(r'^(?P.*(REL CPT DEBITEU).*)'), FrenchTransaction.TYPE_ORDER),
(re.compile(r"^(?P.*(\bAFFRANCHISSEMENT\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(REMISE VIREMENTS MAGNE).*)"), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r"^(?P.*(\bEFFET\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(\bMANIP\.\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(INTERETS SUR REMISE PTF).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(REMISE ESCOMPTE PTF).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(RETENUE DE GARANTIE).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(RESTITUTION RETENUE GARANTIE).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(\bAMENDES\b).*)"), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r"^(?P.*(\bOA\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^.* COTIS ANN (?P.*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(FORFAIT CENT\.RE).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(ENVOI CB).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(RET\.SDD).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(RETOUR PVL ACD EXPERTISE).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(Annulation PAR REJ\/CHQ).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(REJET CHEQUE).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(CHQ PAYE INFRAC).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P^(CHQ IRREGULIER).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(ERREUR REMISE C).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P^(\bREMCHQ\b).*)"), FrenchTransaction.TYPE_DEPOSIT),
(re.compile(r"^(?P^(RETOUR PVL).*)"), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r"^(?P.*(\bTRANSFERT\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(\bCONFIRMATION\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(CAUTION AVEC GAGE).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(\bRAPATRIEMENT\b).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r"^(?P.*(CHANGE REF).*)"), FrenchTransaction.TYPE_BANK),
(re.compile(r'^CARTE DU'), FrenchTransaction.TYPE_CARD),
(re.compile(r'^(VIR (SEPA)?|Vir|VIR.)(?P.*)'), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r'^VIREMENT DE (?P.*)'), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r'^(CHQ|CHEQUE) (?P.*)'), FrenchTransaction.TYPE_CHECK),
(re.compile(r'^(PRLV SEPA|PRELEVEMENT) (?P.*)'), FrenchTransaction.TYPE_ORDER),
]
class HistoryPage(LoggedPage, HTMLPage):
@pagination
@method
class get_operations(Transaction.TransactionsElement):
def next_page(self):
for script in self.page.doc.xpath('//script'):
m = re.search(r"getCodePagination\('(\d+)','(\d+)','([^']+)'.*", script.text or '', re.MULTILINE)
if m:
cur_page = int(m.group(1))
nb_pages = int(m.group(2))
baseurl = m.group(3)
if cur_page < nb_pages:
return baseurl + '&numeroPage=%s&nbrPage=%s' % (cur_page + 1, nb_pages)
head_xpath = '//div[has-class("TableauBicolore")]/table/tr[not(@id)]/td'
item_xpath = '//div[has-class("TableauBicolore")]/table/tr[@id and count(td) > 3]'
col_date = ['Date comptable', "Date d'opération"]
col_vdate = ['Date de valeur']
col_raw = ["Libellé de l'opération"]
class item(Transaction.TransactionElement):
pass
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-themisbanque/modules/themisbanque/test.py 0000664 0000000 0000000 00000001666 14042356110 0031163 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2015 Romain Bignon
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from woob.tools.test import BackendTest
class ThemisBanqueTest(BackendTest):
MODULE = 'themisbanque'
def test_themisbanque(self):
raise NotImplementedError()
|