Commit 034c6477 authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Vincent A

[caissedepargne] improve style

parent b60e3587
......@@ -17,12 +17,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
# flake8: compatible
from weboob.browser.pages import HTMLPage
def fix_form(form):
keys = ['MM$HISTORIQUE_COMPTE$btnCumul', 'Cartridge$imgbtnMessagerie', 'MM$m_CH$ButtonImageFondMessagerie',
'MM$m_CH$ButtonImageMessagerie']
keys = [
'MM$HISTORIQUE_COMPTE$btnCumul', 'Cartridge$imgbtnMessagerie', 'MM$m_CH$ButtonImageFondMessagerie',
'MM$m_CH$ButtonImageMessagerie',
]
for name in keys:
form.pop(name, None)
......
This diff is collapsed.
......@@ -17,8 +17,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
# flake8: compatible
from __future__ import unicode_literals
from collections import Counter
from fnmatch import fnmatch
......@@ -57,7 +58,10 @@ class CenetBrowser(LoginBrowser, StatesMixin):
r'https://.*/login.aspx',
LoginPage,
)
account_login = URL(r'https://(?P<domain>[^/]+)/authentification/manage\?step=account&identifiant=(?P<login>.*)&account=(?P<accountType>.*)', LoginPage)
account_login = URL(
r'https://(?P<domain>[^/]+)/authentification/manage\?step=account&identifiant=(?P<login>.*)&account=(?P<accountType>.*)',
LoginPage
)
cenet_vk = URL(r'https://www.cenet.caisse-epargne.fr/Web/Api/ApiAuthentification.asmx/ChargerClavierVirtuel')
cenet_home = URL(r'/Default.aspx$', CenetHomePage)
cenet_accounts = URL(r'/Web/Api/ApiComptes.asmx/ChargerSyntheseComptes', CenetAccountsPage)
......@@ -127,7 +131,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
post_data = {
'CodeEtablissement': data['codeCaisse'],
'NumeroBad': self.username,
'NumeroUtilisateur': self.nuser
'NumeroUtilisateur': self.nuser,
}
self.location(data['url'], data=post_data, headers={'Referer': 'https://www.cenet.caisse-epargne.fr/'})
......@@ -141,7 +145,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
'contexte': '',
'dateEntree': None,
'donneesEntree': 'null',
'filtreEntree': None
'filtreEntree': None,
}
# get accounts from CenetAccountsPage
......@@ -238,7 +242,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
'contexte': '',
'dateEntree': None,
'donneesEntree': json.dumps(donneesEntree).replace('/', '\\/'),
'filtreEntree': json.dumps(tr._data).replace('/', '\\/')
'filtreEntree': json.dumps(tr._data).replace('/', '\\/'),
}
tr_detail_page = self.cenet_tr_detail.open(json=deferred_data)
......@@ -267,7 +271,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
'contexte': '',
'dateEntree': None,
'donneesEntree': json.dumps(account._hist),
'filtreEntree': None
'filtreEntree': None,
}
self.cenet_account_coming.go(json=data)
......@@ -305,7 +309,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
'contexte': '',
'dateEntree': None,
'donneesEntree': 'null',
'filtreEntree': None
'filtreEntree': None,
}
self.subscription.go(json=json_data)
return self.page.iter_subscription(subscriber=subscriber)
......@@ -328,7 +332,7 @@ class CenetBrowser(LoginBrowser, StatesMixin):
'contexte': '',
'dateEntree': None,
'donneesEntree': 'null',
'filtreEntree': json.dumps(input_filter)
'filtreEntree': json.dumps(input_filter),
}
self.documents.go(json=json_data)
return self.page.iter_documents(sub_id=sub_id, sub_label=subscription.label, username=self.username)
......
......@@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
# flake8: compatible
from __future__ import unicode_literals
from copy import deepcopy
......@@ -41,9 +43,18 @@ from weboob.exceptions import BrowserUnavailable
class Transaction(FrenchTransaction):
PATTERNS = [
(re.compile(r'^CB (?P<text>.*?) FACT (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})', re.IGNORECASE), FrenchTransaction.TYPE_CARD),
(
re.compile(r'^CB (?P<text>.*?) FACT (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})', re.IGNORECASE),
FrenchTransaction.TYPE_CARD,
),
(re.compile(r'^RET(RAIT)? DAB (?P<dd>\d+)-(?P<mm>\d+)-.*', re.IGNORECASE), FrenchTransaction.TYPE_WITHDRAWAL),
(re.compile(r'^RET(RAIT)? DAB (?P<text>.*?) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}) (?P<HH>\d{2})H(?P<MM>\d{2})', re.IGNORECASE), FrenchTransaction.TYPE_WITHDRAWAL),
(
re.compile(
r'^RET(RAIT)? DAB (?P<text>.*?) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}) (?P<HH>\d{2})H(?P<MM>\d{2})',
re.IGNORECASE,
),
FrenchTransaction.TYPE_WITHDRAWAL,
),
(re.compile(r'^VIR(EMENT)?(\.PERIODIQUE)? (?P<text>.*)', re.IGNORECASE), FrenchTransaction.TYPE_TRANSFER),
(re.compile(r'^PRLV (?P<text>.*)', re.IGNORECASE), FrenchTransaction.TYPE_ORDER),
(re.compile(r'^CHEQUE.*', re.IGNORECASE), FrenchTransaction.TYPE_CHECK),
......@@ -53,8 +64,14 @@ class Transaction(FrenchTransaction):
(re.compile(r'^(?P<text>.*)( \d+)? QUITTANCE .*', re.IGNORECASE), FrenchTransaction.TYPE_ORDER),
(re.compile(r'^CB [\d\*]+ TOT DIF .*', re.IGNORECASE), FrenchTransaction.TYPE_CARD_SUMMARY),
(re.compile(r'^CB [\d\*]+ (?P<text>.*)', re.IGNORECASE), FrenchTransaction.TYPE_CARD),
(re.compile(r'^CB (?P<text>.*?) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})', re.IGNORECASE), FrenchTransaction.TYPE_CARD),
(re.compile(r'\*CB (?P<text>.*?) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})', re.IGNORECASE), FrenchTransaction.TYPE_CARD),
(
re.compile(r'^CB (?P<text>.*?) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})', re.IGNORECASE),
FrenchTransaction.TYPE_CARD,
),
(
re.compile(r'\*CB (?P<text>.*?) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})', re.IGNORECASE),
FrenchTransaction.TYPE_CARD,
),
(re.compile(r'^FAC CB (?P<text>.*?) (?P<dd>\d{2})/(?P<mm>\d{2})', re.IGNORECASE), FrenchTransaction.TYPE_CARD),
]
......@@ -65,13 +82,20 @@ class LoginPage(JsonPage):
class CenetLoginPage(HTMLPage):
def login(self, username, password, nuser, codeCaisse, _id, vkpass):
def login(self, username, password, nuser, codeCaisse, vkid, vkpass):
form = self.get_form(id='aspnetForm')
form['__EVENTTARGET'] = "btn_authentifier_securise"
form['__EVENTARGUMENT'] = '{"CodeCaisse":"%s","NumeroBad":"%s","NumeroUsager":"%s",\
"MotDePasse":"%s","IdentifiantClavier":"%s","ChaineConnexion":"%s"}' \
% (codeCaisse, username, nuser, password, _id, vkpass)
form['__EVENTARGUMENT'] = json.dumps(
{
"CodeCaisse": codeCaisse,
"NumeroBad": username,
"NumeroUsager": nuser,
"MotDePasse": password,
"IdentifiantClavier": vkid,
"ChaineConnexion": vkpass,
},
separators=(',', ':')
)
form.submit()
......@@ -305,8 +329,10 @@ class CenetAccountHistoryPage(LoggedPage, CenetJsonPage):
def obj_amount(self):
amount = CleanDecimal(Dict('Montant/Valeur'))(self)
return -amount if Dict('Montant/CodeSens')(self) == "D" else amount
if Dict('Montant/CodeSens')(self) == "D":
return -amount
else:
return amount
def obj__data(self):
return self.el
......@@ -341,15 +367,17 @@ class CenetCardSummaryPage(LoggedPage, CenetJsonPage):
return label
def obj_rdate(self):
rdate = re.search('(FACT\s)(\d{6})', Field('label')(self))
rdate = re.search(r'(FACT\s)(\d{6})', Field('label')(self))
if rdate.group(2):
return Date(dayfirst=True).filter(rdate.group(2))
return NotAvailable
def obj_amount(self):
amount = CleanDecimal(Dict('Montant/Valeur'))(self)
return -amount if Dict('Montant/CodeSens')(self) == "D" else amount
if Dict('Montant/CodeSens')(self) == "D":
return -amount
else:
return amount
class _LogoutPage(HTMLPage):
......@@ -411,7 +439,7 @@ class DownloadDocumentPage(LoggedPage, HTMLPage):
'Numero': document._numero,
'Libelle': document._sub_label.replace(' ', '+'),
'DateArrete': '',
'IdDocument': document._download_id
'IdDocument': document._download_id,
}
form = self.get_form(id='aspnetForm')
form['__EVENTTARGET'] = 'btn_telecharger'
......
......@@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
# flake8: compatible
from weboob.browser import AbstractBrowser
......
......@@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
# flake8: compatible
from __future__ import unicode_literals
import re
......@@ -49,25 +51,36 @@ class CaisseEpargneModule(Module, CapBankWealth, CapBankTransferAddRecipient, Ca
DESCRIPTION = 'Caisse d\'Épargne'
LICENSE = 'LGPLv3+'
BROWSER = ProxyBrowser
website_choices = OrderedDict([(k, u'%s (%s)' % (v, k)) for k, v in sorted({
'www.caisse-epargne.fr': u'Caisse d\'Épargne',
'www.banquebcp.fr': u'Banque BCP',
}.items(), key=lambda k_v: (k_v[1], k_v[0]))])
website_choices = {
'www.caisse-epargne.fr': u"Caisse d'Épargne",
'www.banquebcp.fr': u'Banque BCP',
}
website_choices = OrderedDict(
[
(k, u'%s (%s)' % (v, k))
for k, v in sorted(
website_choices.items(),
key=lambda k_v: (k_v[1], k_v[0])
)
]
)
CONFIG = BackendConfig(
Value('website', label='Banque', choices=website_choices, default='www.caisse-epargne.fr'),
Value('website', label='Banque', choices=website_choices, default='www.caisse-epargne.fr'),
ValueBackendPassword('login', label='Identifiant client', masked=False),
ValueBackendPassword('password', label='Code personnel', regexp='\d+'),
Value('nuser', label='User ID (optional)', default='', regexp='[A-Z\d]{0,8}'),
ValueBackendPassword('password', label='Code personnel', regexp=r'\d+'),
Value('nuser', label='User ID (optional)', default='', regexp=r'[A-Z0-9]{0,8}'),
)
accepted_document_types = (DocumentTypes.STATEMENT, DocumentTypes.OTHER,)
def create_default_browser(self):
return self.create_browser(nuser=self.config['nuser'].get(),
username=self.config['login'].get(),
password=self.config['password'].get(),
domain=self.config['website'].get(),
weboob=self.weboob)
return self.create_browser(
nuser=self.config['nuser'].get(),
username=self.config['login'].get(),
password=self.config['password'].get(),
domain=self.config['website'].get(),
weboob=self.weboob
)
def iter_accounts(self):
for account in self.browser.get_accounts_list():
......@@ -106,16 +119,23 @@ class CaisseEpargneModule(Module, CapBankWealth, CapBankTransferAddRecipient, Ca
return self.browser.otp_sms_continue_transfer(transfer, **params)
self.logger.info('Going to do a new transfer')
transfer.label = ' '.join(w for w in re.sub('[^0-9a-zA-Z/\-\?:\(\)\.,\'\+ ]+', '', transfer.label).split()).upper()
transfer.label = re.sub(r"[^0-9A-Z/?:().,'+ -]+", '', transfer.label.upper())
transfer.label = re.sub(r'\s+', ' ', transfer.label)
if transfer.account_iban:
account = find_object(self.iter_accounts(), iban=transfer.account_iban, error=AccountNotFound)
else:
account = find_object(self.iter_accounts(), id=transfer.account_id, error=AccountNotFound)
if transfer.recipient_iban:
recipient = find_object(self.iter_transfer_recipients(account.id), iban=transfer.recipient_iban, error=RecipientNotFound)
recipient = find_object(
self.iter_transfer_recipients(account.id), iban=transfer.recipient_iban,
error=RecipientNotFound
)
else:
recipient = find_object(self.iter_transfer_recipients(account.id), id=transfer.recipient_id, error=RecipientNotFound)
recipient = find_object(
self.iter_transfer_recipients(account.id), id=transfer.recipient_id,
error=RecipientNotFound
)
transfer.amount = transfer.amount.quantize(Decimal(10) ** -2)
......@@ -125,7 +145,6 @@ class CaisseEpargneModule(Module, CapBankWealth, CapBankTransferAddRecipient, Ca
return self.browser.execute_transfer(transfer)
def new_recipient(self, recipient, **params):
# recipient.label = ' '.join(w for w in re.sub('[^0-9a-zA-Z:\/\-\?\(\)\.,\'\+ ]+', '', recipient.label).split())
return self.browser.new_recipient(recipient, **params)
def iter_resources(self, objs, split_path):
......
This diff is collapsed.
......@@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
# flake8: compatible
from __future__ import unicode_literals
import re
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment