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

[bnporc] reformat with yapf

Also try to get rid of some "JSON()" calls.
parent bac984c8
......@@ -17,7 +17,6 @@
# 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 .module import BNPorcModule
__all__ = ['BNPorcModule']
......@@ -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/>.
# yapf-compatible
from __future__ import unicode_literals
from datetime import date, timedelta
......@@ -28,7 +30,6 @@ from weboob.tools.compat import basestring
from .pages import LoginPage, AccountsPage, HistoryPage
__all__ = ['BNPCompany']
......@@ -49,7 +50,6 @@ class BNPCompany(LoginBrowser):
self.page.login(self.username, self.password)
@need_login
def iter_accounts(self):
self.accounts.go()
......@@ -74,10 +74,11 @@ class BNPCompany(LoginBrowser):
@need_login
def iter_history(self, account):
return self.get_transactions(account.id,
'Comptable',
(date.today() - timedelta(days=90)).strftime('%Y%m%d'),
date.today().strftime('%Y%m%d'))
return self.get_transactions(
account.id,
'Comptable', (date.today() - timedelta(days=90)).strftime('%Y%m%d'),
date.today().strftime('%Y%m%d')
)
@need_login
def iter_documents(self, subscription):
......@@ -89,9 +90,7 @@ class BNPCompany(LoginBrowser):
@need_login
def iter_coming_operations(self, account):
return self.get_transactions(account.id,
'Previsionnel',
(date.today().strftime('%Y%m%d')))
return self.get_transactions(account.id, 'Previsionnel', (date.today().strftime('%Y%m%d')))
@need_login
def iter_investment(self, account):
......
......@@ -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/>.
# yapf-compatible
from __future__ import unicode_literals
from io import BytesIO
......@@ -32,19 +34,20 @@ from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardEr
class BNPVirtKeyboard(MappedVirtKeyboard):
symbols = {'0': 'ff069462836e30a39c911034048f5bb3',
'1': '7969f04e4e82eaefa2ce7a9a23c26178',
'2': '1e6020f97ca1c3ce3da4f39ded15d67d',
'3': 'f84284b40aea93c24814e23e14e76cc8',
'4': '88bab262d4b344c0ef8f06ddd01adbcf',
'5': '0a270764fc5d8334bcb55053432b26cb',
'6': 'e6a4444a6c752cd3e655f2883e530080',
'7': '933d4ca5df6b2b3df2dea00a21a3fed6',
'8': ['f28b918777d21a5fde2bffb9899e2138', 'a97e6e27159084d50f8ef00548b70252'],
'9': 'be751b77af0d998ab4c2cfd38455b2a6',
}
color=(0,0,0)
symbols = {
'0': 'ff069462836e30a39c911034048f5bb3',
'1': '7969f04e4e82eaefa2ce7a9a23c26178',
'2': '1e6020f97ca1c3ce3da4f39ded15d67d',
'3': 'f84284b40aea93c24814e23e14e76cc8',
'4': '88bab262d4b344c0ef8f06ddd01adbcf',
'5': '0a270764fc5d8334bcb55053432b26cb',
'6': 'e6a4444a6c752cd3e655f2883e530080',
'7': '933d4ca5df6b2b3df2dea00a21a3fed6',
'8': ['f28b918777d21a5fde2bffb9899e2138', 'a97e6e27159084d50f8ef00548b70252'],
'9': 'be751b77af0d998ab4c2cfd38455b2a6',
}
color = (0, 0, 0)
def __init__(self, basepage):
img = basepage.doc.xpath('//img[@id="gridpass_img"]')[0]
......
......@@ -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/>.
# yapf-compatible
from __future__ import unicode_literals
from datetime import datetime
......@@ -36,27 +38,37 @@ from .pages import (
PasswordExpiredPage, TransactionPage, MarketPage, InvestPage,
)
__all__ = ['BNPEnterprise']
class BNPEnterprise(LoginBrowser):
BASEURL = 'https://secure1.entreprises.bnpparibas.net'
login = URL('/sommaire/jsp/identification.jsp',
'/sommaire/generateImg', LoginPage)
login = URL('/sommaire/jsp/identification.jsp', '/sommaire/generateImg', LoginPage)
auth = URL('/sommaire/PseMenuServlet', AuthPage)
accounts = URL('/NCCPresentationWeb/e10_soldes/liste_soldes.do', AccountsPage)
account_history_view = URL('/NCCPresentationWeb/e10_soldes/init.do\?nccIdSelected=NCC_Soldes',
'/NCCPresentationWeb/e11_releve_op/init.do\?identifiant=(?P<identifiant>)'
'&typeSolde=(?P<type_solde>)&typeReleve=(?P<type_releve>)&typeDate=(?P<type_date>)'
'&dateMin=(?P<date_min>)&dateMax=(?P<date_max>)&ajax=true',
'/NCCPresentationWeb/e11_releve_op/init.do', AccountHistoryViewPage)
account_coming_view = URL('/NCCPresentationWeb/m04_selectionCompteGroupe/init.do\?type=compte&identifiant=(?P<identifiant>)', AccountHistoryViewPage)
account_history = URL('/NCCPresentationWeb/e11_releve_op/listeOperations.do\?identifiant=(?P<identifiant>)&typeSolde=(?P<type_solde>)&typeReleve=(?P<type_releve>)&typeDate=(?P<type_date>)&dateMin=(?P<date_min>)&dateMax=(?P<date_max>)&ajax=true',
'/NCCPresentationWeb/e11_releve_op/listeOperations.do', AccountHistoryPage)
account_coming = URL('/NCCPresentationWeb/e12_rep_cat_op/listOperations.do\?periode=date_valeur&identifiant=(?P<identifiant>)',
'/NCCPresentationWeb/e12_rep_cat_op/listOperations.do', AccountHistoryPage)
account_history_view = URL(
'/NCCPresentationWeb/e10_soldes/init.do\?nccIdSelected=NCC_Soldes',
'/NCCPresentationWeb/e11_releve_op/init.do\?identifiant=(?P<identifiant>)'
'&typeSolde=(?P<type_solde>)&typeReleve=(?P<type_releve>)&typeDate=(?P<type_date>)'
'&dateMin=(?P<date_min>)&dateMax=(?P<date_max>)&ajax=true',
'/NCCPresentationWeb/e11_releve_op/init.do',
AccountHistoryViewPage
)
account_coming_view = URL(
'/NCCPresentationWeb/m04_selectionCompteGroupe/init.do\?type=compte&identifiant=(?P<identifiant>)',
AccountHistoryViewPage
)
account_history = URL(
'/NCCPresentationWeb/e11_releve_op/listeOperations.do\?identifiant=(?P<identifiant>)&typeSolde=(?P<type_solde>)&typeReleve=(?P<type_releve>)&typeDate=(?P<type_date>)&dateMin=(?P<date_min>)&dateMax=(?P<date_max>)&ajax=true',
'/NCCPresentationWeb/e11_releve_op/listeOperations.do',
AccountHistoryPage
)
account_coming = URL(
'/NCCPresentationWeb/e12_rep_cat_op/listOperations.do\?periode=date_valeur&identifiant=(?P<identifiant>)',
'/NCCPresentationWeb/e12_rep_cat_op/listOperations.do',
AccountHistoryPage
)
transaction_detail = URL(r'/NCCPresentationWeb/e21/getOptBDDF.do', TransactionPage)
invest = URL(r'/opcvm/lister-composition/afficher.do', InvestPage)
......@@ -139,7 +151,11 @@ class BNPEnterprise(LoginBrowser):
# To avoid duplicated transactions we exit as soon a transaction is not within the expected timeframe
for date in rrule(MONTHLY, dtstart=(datetime.now() - relativedelta(months=11)), until=datetime.now())[::-1]:
params = dict(identifiant=account.iban, type_solde='C', type_releve='Previsionnel', type_date='O',
params = dict(
identifiant=account.iban,
type_solde='C',
type_releve='Previsionnel',
type_date='O',
date_min=(date + relativedelta(days=1) - relativedelta(months=1)).strftime(dformat),
date_max=date.strftime(dformat)
)
......@@ -153,8 +169,9 @@ class BNPEnterprise(LoginBrowser):
continue
if transaction.date > date:
self.logger.debug('transaction not within expected timeframe, stop iterating history: %r',
transaction.to_dict())
self.logger.debug(
'transaction not within expected timeframe, stop iterating history: %r', transaction.to_dict()
)
return
yield transaction
......
......@@ -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/>.
# yapf-compatible
from __future__ import unicode_literals
import re
......@@ -39,22 +41,24 @@ from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardEr
from weboob.capabilities import NotAvailable
from weboob.exceptions import BrowserPasswordExpired, BrowserForbidden
def fromtimestamp(milliseconds):
return datetime.fromtimestamp(milliseconds/1000)
return datetime.fromtimestamp(milliseconds / 1000)
class BNPVirtKeyboard(MappedVirtKeyboard):
symbols = {'0': '8adee734aaefb163fb008d26bb9b3a42',
'1': 'dad45ef18a75200030073ab102155e2f',
'2': '6cb4c69361f5ce32b68b477db98dd0fb',
'3': 'aa9f2d90c8112b84805d908938eefff7',
'4': '5aa9329aceab4318c2c96130915e87b7',
'5': 'd9fbfdf531ad888a9d79855536905d23',
'6': '50ce19be233ac07bebb59a16a3b9d4a7',
'7': '3a1f932237aab949fa6c59565823218b',
'8': 'd46cf28408db75caa915edb871ea573a',
'9': '87686fd75d283905d7651e1098db0882',
}
symbols = {
'0': '8adee734aaefb163fb008d26bb9b3a42',
'1': 'dad45ef18a75200030073ab102155e2f',
'2': '6cb4c69361f5ce32b68b477db98dd0fb',
'3': 'aa9f2d90c8112b84805d908938eefff7',
'4': '5aa9329aceab4318c2c96130915e87b7',
'5': 'd9fbfdf531ad888a9d79855536905d23',
'6': '50ce19be233ac07bebb59a16a3b9d4a7',
'7': '3a1f932237aab949fa6c59565823218b',
'8': 'd46cf28408db75caa915edb871ea573a',
'9': '87686fd75d283905d7651e1098db0882',
}
color = (0, 0, 0)
......@@ -106,8 +110,8 @@ class PasswordExpiredPage(HTMLPage):
class AccountsPage(LoggedPage, JsonPage):
TYPES = {
'Compte chèque': Account.TYPE_CHECKING,
'Compte à vue': Account.TYPE_CHECKING,
'Compte chèque': Account.TYPE_CHECKING,
'Compte à vue': Account.TYPE_CHECKING,
}
@method
......@@ -121,9 +125,7 @@ class AccountsPage(LoggedPage, JsonPage):
return CleanText(Dict('numeroCompte'))(self)[2:]
obj_balance = Eval(
lambda x, y: x / 10**y,
CleanDecimal(Dict('soldeComptable')),
CleanDecimal(Dict('decSoldeComptable'))
lambda x, y: x / 10 ** y, CleanDecimal(Dict('soldeComptable')), CleanDecimal(Dict('decSoldeComptable'))
)
obj_label = CleanText(Dict('libelleCompte'))
obj_currency = CleanText(Dict('deviseTenue'))
......@@ -133,9 +135,7 @@ class AccountsPage(LoggedPage, JsonPage):
return self.page.TYPES.get(Dict('libelleType')(self), Account.TYPE_UNKNOWN)
def obj_coming(self):
page = self.page.browser.open(
BrowserURL('account_coming', identifiant=Field('iban'))(self)
).page
page = self.page.browser.open(BrowserURL('account_coming', identifiant=Field('iban'))(self)).page
nb_decimal = 0
if 'nb_dec' in Dict('infoOperationsAvenir/cumulTotal')(page.doc):
......@@ -144,7 +144,7 @@ class AccountsPage(LoggedPage, JsonPage):
nb_decimal = Dict('infoOperationsAvenir/cumulTotal/nbDec')
coming = Eval(
lambda x, y: x / 10**y,
lambda x, y: x / 10**y, # yapf: disable
CleanDecimal(Dict('infoOperationsAvenir/cumulTotal/montant', default='0')),
CleanDecimal(nb_decimal)
)(page.doc)
......@@ -161,7 +161,6 @@ class AccountHistoryViewPage(LoggedPage, HTMLPage):
class BnpHistoryItem(ItemElement):
def obj_raw(self):
if self.el.get('nature.libelle') and self.el.get('libelle'):
return "%s %s" % (
......@@ -195,10 +194,12 @@ class CardItemElement(ItemElement):
return
url = self.page.browser.transaction_detail.build()
return self.page.browser.open(url, is_async=True, data={
'type_mvt': self.detail_type_mvt,
'numero_mvt': Field('_trid')(self),
})
return self.page.browser.open(
url, is_async=True, data={
'type_mvt': self.detail_type_mvt,
'numero_mvt': Field('_trid')(self),
}
)
class AccountHistoryPage(LoggedPage, JsonPage):
......@@ -257,10 +258,10 @@ class AccountHistoryPage(LoggedPage, JsonPage):
def obj_type(self):
type = self.page.TYPES.get(Dict('nature/codefamille')(self), Transaction.TYPE_UNKNOWN)
if (
(type == Transaction.TYPE_CARD and re.search(r' RELEVE DU \d+\.', Field('raw')(self))) or
(type == Transaction.TYPE_UNKNOWN and re.search(r'FACTURE CARTE AFFAIRES \w{16} SUIVANT RELEVE DU \d{2}.\d{2}.\d{4}', Field('raw')(self)))
):
if ((type == Transaction.TYPE_CARD and re.search(r' RELEVE DU \d+\.', Field('raw')(self))) or (
type == Transaction.TYPE_UNKNOWN and
re.search(r'FACTURE CARTE AFFAIRES \w{16} SUIVANT RELEVE DU \d{2}.\d{2}.\d{4}', Field('raw')(self))
)):
return Transaction.TYPE_CARD_SUMMARY
return type
......@@ -289,14 +290,9 @@ class AccountHistoryPage(LoggedPage, JsonPage):
return fromtimestamp(Dict('dateValeur')(self))
def obj_amount(self):
decimal_nb = Dict('montant/nbDec', default=None)(self)\
or Dict('montant/nb_dec')(self)
decimal_nb = (Dict('montant/nbDec', default=None)(self) or Dict('montant/nb_dec')(self))
return Eval(
lambda x, y: x / 10**y,
CleanDecimal(Dict('montant/montant')),
decimal_nb
)(self)
return Eval(lambda x, y: x / 10 ** y, CleanDecimal(Dict('montant/montant')), decimal_nb)(self)
obj__trid = Dict('id')
......@@ -328,11 +324,7 @@ class AccountHistoryPage(LoggedPage, JsonPage):
decimal_nb = Dict('montantMvmt/nbDec', default=None)(self)\
or Dict('montantMvmt/nb_dec')(self)
return Eval(
lambda x, y: x / 10**y,
CleanDecimal(Dict('montantMvmt/montant')),
decimal_nb
)(self)
return Eval(lambda x, y: x / 10 ** y, CleanDecimal(Dict('montantMvmt/montant')), decimal_nb)(self)
obj__trid = Dict('idMouvement')
......@@ -343,14 +335,16 @@ class TransactionPage(LoggedPage, JsonPage):
class MarketPage(LoggedPage, HTMLPage):
TYPES = {
'comptes de titres': Account.TYPE_MARKET,
'comptes de titres': Account.TYPE_MARKET,
}
@method
class iter_market_accounts(TableElement):
def condition(self):
return not self.el.xpath('//table[@id="table-portefeuille"]//tr/td[contains(text(), "Aucun portefeuille à afficher") \
or contains(text(), "No portfolio to display")]')
return not self.el.xpath(
'//table[@id="table-portefeuille"]//tr/td[contains(text(), "Aucun portefeuille à afficher") \
or contains(text(), "No portfolio to display")]'
)
item_xpath = '//table[@id="table-portefeuille"]/tbody[@class="main-content"]/tr'
head_xpath = '//table[@id="table-portefeuille"]/thead/tr/th/label'
......@@ -384,7 +378,9 @@ class MarketPage(LoggedPage, HTMLPage):
def get_id(self, label):
id_simple = re.search(r'[0-9]+', label).group(0)
for options in self.doc.xpath('//div[@class="filterbox-content hide"]//select[@id="numero-compte-titre"]//option'):
for options in self.doc.xpath(
'//div[@class="filterbox-content hide"]//select[@id="numero-compte-titre"]//option'
):
if id_simple in CleanText(options)(self.doc):
return CleanText(options.xpath('./@value'))(self)
......@@ -404,7 +400,6 @@ class InvestPage(LoggedPage, HTMLPage):
obj__parent = CleanText('//h3/span[span[@class="info-cheque"]]', children=False)
obj__unique = True
@method
class iter_investment(TableElement):
item_xpath = '//table[@class="csv-data-container hide"]//tr'
......@@ -416,13 +411,11 @@ class InvestPage(LoggedPage, HTMLPage):
col_unitvalue = 'Valeur de la part'
col_valuation = 'Valorisation'
col_diff = '+/- value'
"""
Note: Pagination is not handled yet for investments, if we find a
customer with more than 10 invests we might have to handle clicking
on the button to get 50 invests per page or check if there is a link.
"""
class item(ItemElement):
klass = Investment
......@@ -432,7 +425,11 @@ class InvestPage(LoggedPage, HTMLPage):
obj_unitvalue = CleanDecimal(TableCell('unitvalue'), replace_dots=True)
obj_valuation = CleanDecimal(TableCell('valuation'), replace_dots=True)
obj_diff = CleanDecimal(TableCell('diff'), replace_dots=True)
obj_code_type = lambda self: Investment.CODE_TYPE_ISIN if Field('code')(self) is not NotAvailable else NotAvailable
def obj_code_type(self):
if Field('code')(self):
return Investment.CODE_TYPE_ISIN
return NotAvailable
def obj_code(self):
string = CleanText(TableCell('label'))(self)
......
......@@ -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/>.
# yapf-compatible
from __future__ import unicode_literals
import re
......@@ -42,11 +44,12 @@ from .enterprise.browser import BNPEnterprise
from .company.browser import BNPCompany
from .pp.browser import BNPPartPro, HelloBank
__all__ = ['BNPorcModule']
class BNPorcModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapMessages, CapContact, CapProfile, CapDocument):
class BNPorcModule(
Module, CapBankWealth, CapBankTransferAddRecipient, CapMessages, CapContact, CapProfile, CapDocument
):
NAME = 'bnporc'
MAINTAINER = u'Romain Bignon'
EMAIL = 'romain@weboob.org'
......@@ -54,15 +57,22 @@ class BNPorcModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapMessag
LICENSE = 'LGPLv3+'
DESCRIPTION = 'BNP Paribas'
CONFIG = BackendConfig(
ValueBackendPassword('login', label=u'Numéro client', masked=False),
ValueBackendPassword('password', label=u'Code secret', regexp='^(\d{6})$'),
ValueBool('rotating_password', label=u'Automatically renew password every 100 connections', default=False),
ValueBool('digital_key', label=u'User with digital key have to add recipient with digital key', default=False),
Value('website', label='Type de compte', default='pp',
choices={'pp': 'Particuliers/Professionnels',
'hbank': 'HelloBank',
'ent': 'Entreprises',
'ent2': 'Entreprises et PME (nouveau site)'}))
ValueBackendPassword('login', label=u'Numéro client', masked=False),
ValueBackendPassword('password', label=u'Code secret', regexp='^(\d{6})$'),
ValueBool('rotating_password', label=u'Automatically renew password every 100 connections', default=False),
ValueBool('digital_key', label=u'User with digital key have to add recipient with digital key', default=False),
Value(
'website',
label='Type de compte',
default='pp',
choices={
'pp': 'Particuliers/Professionnels',
'hbank': 'HelloBank',
'ent': 'Entreprises',
'ent2': 'Entreprises et PME (nouveau site)'
}
)
)
STORAGE = {'seen': []}
accepted_document_types = (
......@@ -141,7 +151,9 @@ class BNPorcModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapMessag
recipient = strict_find_object(self.iter_transfer_recipients(account.id), iban=transfer.recipient_iban)
if not recipient:
recipient = strict_find_object(self.iter_transfer_recipients(account.id), id=transfer.recipient_id, error=RecipientNotFound)
recipient = strict_find_object(
self.iter_transfer_recipients(account.id), id=transfer.recipient_id, error=RecipientNotFound
)
assert account.id.isdigit()
# quantize to show 2 decimals.
......
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/>.
# yapf-compatible
from __future__ import unicode_literals
import re
......@@ -73,13 +75,15 @@ class ItemDocument(ItemElement):
def obj_label(self):
if 'ibanCrypte' in self.el:
return '%s %s N° %s' % (Dict('dateDoc')(self), Dict('libelleSousFamille')(self), Dict('numeroCompteAnonymise')(self))
return '%s %s N° %s' % (
Dict('dateDoc')(self), Dict('libelleSousFamille')(self), Dict('numeroCompteAnonymise')(self)
)
else:
return '%s %s N° %s' % (Dict('dateDoc')(self), Dict('libelleSousFamille')(self), Dict('idContrat')(self))
def obj_url(self):
keys_to_copy = {
'idDocument' :'idDoc',
'idDocument': 'idDoc',
'dateDocument': 'dateDoc',
'idLocalisation': 'idLocalisation',
'viDocDocument': 'viDocDocument',
......
This diff is collapsed.
......@@ -17,7 +17,6 @@
# 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 weboob.tools.test import BackendTest
from random import choice
......
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