Commit b35ea374 authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Vincent A

[lcl] improve code style

parent 9e131dad
......@@ -17,6 +17,7 @@
# 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
......@@ -26,7 +27,6 @@ from datetime import datetime, timedelta, date
from functools import wraps
from dateutil.relativedelta import relativedelta
from weboob.exceptions import (
BrowserIncorrectPassword, BrowserUnavailable,
AuthMethodNotImplemented, ActionNeeded,
......@@ -137,7 +137,10 @@ class LCLBrowser(LoginBrowser, StatesMixin):
av_list = URL(r'https://assurance-vie-et-prevoyance.secure.lcl.fr/rest/assurance/synthesePartenaire', AVListPage)
avdetail = URL(r'https://assurance-vie-et-prevoyance.secure.lcl.fr/consultation/epargne', AVDetailPage)
av_history = URL(r'https://assurance-vie-et-prevoyance.secure.lcl.fr/rest/assurance/historique', AVHistoryPage)
av_investments = URL(r'https://assurance-vie-et-prevoyance.secure.lcl.fr/rest/detailEpargne/contrat/(?P<life_insurance_id>\w+)', AVInvestmentsPage)
av_investments = URL(
r'https://assurance-vie-et-prevoyance.secure.lcl.fr/rest/detailEpargne/contrat/(?P<life_insurance_id>\w+)',
AVInvestmentsPage
)
loans = URL(r'/outil/UWCR/SynthesePar/', LoansPage)
loans_pro = URL(r'/outil/UWCR/SynthesePro/', LoansProPage)
......@@ -168,8 +171,11 @@ class LCLBrowser(LoginBrowser, StatesMixin):
profile = URL(r'/outil/UWIP/Accueil/rafraichir', ProfilePage)
deposit = URL(r'/outil/UWPL/CompteATerme/accesSynthese',
r'/outil/UWPL/DetailCompteATerme/accesDetail', DepositPage)
deposit = URL(
r'/outil/UWPL/CompteATerme/accesSynthese',
r'/outil/UWPL/DetailCompteATerme/accesDetail',
DepositPage
)
__states__ = ('contracts', 'current_contract', 'parsed_contracts')
......@@ -371,16 +377,26 @@ class LCLBrowser(LoginBrowser, StatesMixin):
continue
self.location('/outil/UWRI/Accueil/')
if self.no_perm.is_here():
self.logger.warning('RIB is unavailable.')
elif self.page.has_iban_choice():
self.rib.go(data={'compte': '%s/%s/%s' % (a.id[0:5], a.id[5:11], a.id[11:])})
if self.rib.is_here():
iban = self.page.get_iban()
a.iban = iban if iban and a.id[11:] in iban else NotAvailable
if iban and a.id[11:] in iban:
a.iban = iban
else:
a.iban = NotAvailable
else:
iban = self.page.check_iban_by_account(a.id)
a.iban = iban if iban is not None else NotAvailable
if iban:
a.iban = iban
else:
a.iban = NotAvailable
self.update_accounts(a)
# retrieve loans accounts
......@@ -460,7 +476,11 @@ class LCLBrowser(LoginBrowser, StatesMixin):
if not account.ownership:
if account.parent and account.parent.ownership:
account.ownership = account.parent.ownership
elif re.search(r'(m|mr|me|mme|mlle|mle|ml)\.? (.*)\bou (m|mr|me|mme|mlle|mle|ml)\b(.*)', account.label, re.IGNORECASE):
elif re.search(
r'(m|mr|me|mme|mlle|mle|ml)\.? (.*)\bou (m|mr|me|mme|mlle|mle|ml)\b(.*)',
account.label,
re.IGNORECASE
):
account.ownership = AccountOwnership.CO_OWNER
elif all(n in account.label for n in owner_name.split()):
account.ownership = AccountOwnership.OWNER
......@@ -479,10 +499,13 @@ class LCLBrowser(LoginBrowser, StatesMixin):
def get_history(self, account):
if hasattr(account, '_market_link') and account._market_link:
self.connexion_bourse()
self.location(account._link_id, params={
'nump': account._market_id,
})
self.location(
account._link_id, params={
'nump': account._market_id,
}
)
self.page.get_fullhistory()
for tr in self.page.iter_history():
yield tr
self.deconnexion_bourse()
......@@ -682,7 +705,7 @@ class LCLBrowser(LoginBrowser, StatesMixin):
# Send sms to user.
data = [
('telChoisi', 'MOBILE'),
('_', int(round(time.time() * 1000)))
('_', int(round(time.time() * 1000))),
]
self.location('/outil/UWAF/Otp/envoiCodeOtp', params=data)
self.page.check_error()
......
......@@ -17,6 +17,7 @@
# 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 LoginBrowser, URL, need_login
from weboob.exceptions import BrowserIncorrectPassword
......@@ -29,10 +30,16 @@ class LCLEnterpriseBrowser(LoginBrowser):
BASEURL = 'https://entreprises.secure.lcl.fr'
pass_expired = URL('/outil/IQEN/Authentication/forcerChangePassword', PassExpiredPage)
login = URL('/outil/IQEN/Authentication/indexRedirect',
'/outil/IQEN/Authentication/(?P<page>.*)', LoginPage)
movements = URL('/outil/IQMT/mvt.Synthese/syntheseMouvementPerso',
'/outil/IQMT/mvt.Synthese', MovementsPage)
login = URL(
'/outil/IQEN/Authentication/indexRedirect',
'/outil/IQEN/Authentication/(?P<page>.*)',
LoginPage
)
movements = URL(
'/outil/IQMT/mvt.Synthese/syntheseMouvementPerso',
'/outil/IQMT/mvt.Synthese',
MovementsPage
)
profile = URL('/outil/IQGA/FicheUtilisateur/maFicheUtilisateur', ProfilePage)
def __init__(self, *args, **kwargs):
......@@ -40,7 +47,6 @@ class LCLEnterpriseBrowser(LoginBrowser):
self.accounts = None
self.owner_type = AccountOwnerType.ORGANIZATION
def deinit(self):
if self.page and self.page.logged:
self.login.go(page="logout")
......@@ -51,10 +57,11 @@ class LCLEnterpriseBrowser(LoginBrowser):
def do_login(self):
self.login.go().login(self.username, self.password)
error = self.page.get_error() if self.login.is_here() else False
if self.login.is_here():
error = self.page.get_error()
if error:
raise BrowserIncorrectPassword(error)
if error:
raise BrowserIncorrectPassword(error)
@need_login
def get_accounts_list(self):
......
......@@ -18,8 +18,9 @@
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
import re, requests
import re
import requests
from weboob.browser.pages import HTMLPage, LoggedPage, pagination
from weboob.browser.elements import ListElement, ItemElement, TableElement, method
from weboob.browser.filters.standard import CleanText, Date, CleanDecimal, Env
......@@ -52,7 +53,7 @@ class LoginPage(HTMLPage):
class MovementsPage(LoggedPage, HTMLPage):
def get_changecompte(self, link):
form = self.get_form('//form[contains(@action, "changeCompte")]')
m = re.search('\'(\d+).*\'(\d+)', link)
m = re.search(r"'(\d+).*'(\d+)", link)
form['perimetreMandatParentData'] = m.group(1)
form['perimetreMandatEnfantData'] = m.group(2)
# Can't do multi with async because of inconsistency...
......@@ -93,14 +94,16 @@ class MovementsPage(LoggedPage, HTMLPage):
obj__data = Env('data')
def parse(self, el):
page, url, data = self.page.get_changecompte(Link('.')(self)) if self.env['multi'] else (self.page, None, None)
page, url, data = (self.page, None, None)
if self.env['multi']:
page, url, data = self.page.get_changecompte(Link('.')(self))
balance_xpath = '//div[contains(text(),"Solde")]/strong'
self.env['balance'] = MyDecimal().filter(page.doc.xpath(balance_xpath))
self.env['currency'] = Account.get_currency(CleanText().filter(page.doc.xpath(balance_xpath)))
self.env['url'] = url
self.env['data'] = data
@pagination
@method
class iter_history(TableElement):
......@@ -114,7 +117,7 @@ class MovementsPage(LoggedPage, HTMLPage):
def next_page(self):
url = Link('//a[contains(text(), "Page suivante")]', default=None)(self)
if url:
m = re.search('\s+\'([^\']+).*\'(\d+)', url)
m = re.search(r"\s+'([^']+).*'(\d+)", url)
return requests.Request("POST", m.group(1), data={'numPage': m.group(2)})
class item(ItemElement):
......@@ -127,7 +130,9 @@ class MovementsPage(LoggedPage, HTMLPage):
def obj_amount(self):
credit = MyDecimal(TableCell('credit'))(self)
debit = MyDecimal(TableCell('debit'))(self)
return credit if credit else -debit
if credit:
return credit
return -debit
class ProfilePage(LoggedPage, HTMLPage):
......
......@@ -17,6 +17,7 @@
# 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 decimal import Decimal
from functools import wraps
......@@ -65,31 +66,45 @@ class LCLModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapContact,
VERSION = '2.1'
DESCRIPTION = u'LCL'
LICENSE = 'LGPLv3+'
CONFIG = BackendConfig(ValueBackendPassword('login', label='Identifiant', masked=False),
ValueBackendPassword('password', label='Code personnel'),
Value('website', label='Type de compte', default='par',
choices={'par': 'Particuliers',
'pro': 'Professionnels',
'ent': 'Entreprises',
'esp': 'Espace Pro'},
aliases={'elcl': 'par'}))
CONFIG = BackendConfig(
ValueBackendPassword('login', label='Identifiant', masked=False),
ValueBackendPassword('password', label='Code personnel'),
Value(
'website',
label='Type de compte',
default='par',
choices={
'par': 'Particuliers',
'pro': 'Professionnels',
'ent': 'Entreprises',
'esp': 'Espace Pro',
},
aliases={'elcl': 'par'}
)
)
BROWSER = LCLBrowser
accepted_document_types = (DocumentTypes.STATEMENT, DocumentTypes.NOTICE, DocumentTypes.REPORT, DocumentTypes.OTHER)
def create_default_browser(self):
# assume all `website` option choices are defined here
browsers = {'par': LCLBrowser,
'pro': LCLProBrowser,
'ent': LCLEnterpriseBrowser,
'esp': LCLEspaceProBrowser}
browsers = {
'par': LCLBrowser,
'pro': LCLProBrowser,
'ent': LCLEnterpriseBrowser,
'esp': LCLEspaceProBrowser,
}
website_value = self.config['website']
self.BROWSER = browsers.get(website_value.get(),
browsers[website_value.default])
return self.create_browser(self.config['login'].get(),
self.config['password'].get())
self.BROWSER = browsers.get(
website_value.get(),
browsers[website_value.default]
)
return self.create_browser(
self.config['login'].get(),
self.config['password'].get()
)
def iter_accounts(self):
return self.browser.get_accounts_list()
......
This diff is collapsed.
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