Commit 3b6ed034 authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Vincent A

[cragr] Moved files from the /cragr/api file to the /cragr file

There is only one browser now, no need to keep the /api folder.
Also added a comment on how we build the BASEURL from the website
parent 72d9710a
......@@ -27,7 +27,6 @@ import re
from import Account, Loan, Per, PerProviderType, Transaction, AccountNotFound, RecipientNotFound
from weboob.capabilities.base import empty, NotAvailable, strict_find_object
from weboob.browser import LoginBrowser, URL, need_login
from weboob.browser.switch import SiteSwitch
from weboob.browser.exceptions import ServerError, ClientError, BrowserHTTPNotFound, HTTPNotFound
from weboob.exceptions import BrowserUnavailable, BrowserIncorrectPassword, ActionNeeded
from import is_iban_valid
......@@ -37,7 +36,7 @@ from import retry
from .pages import (
LoginPage, LoggedOutPage, KeypadPage, SecurityPage, ContractsPage, FirstConnectionPage, AccountsPage, AccountDetailsPage,
TokenPage, ChangePasswordPage, IbanPage, HistoryPage, CardsPage, CardHistoryPage, NetfincaRedirectionPage, PredicaRedirectionPage,
PredicaInvestmentsPage, ProfilePage, ProfileDetailsPage, ProProfileDetailsPage, LifeInsuranceInvestmentsPage, OldWebsitePage,
PredicaInvestmentsPage, ProfilePage, ProfileDetailsPage, ProProfileDetailsPage, LifeInsuranceInvestmentsPage,
from .transfer_pages import (
RecipientsPage, TransferPage, TransferTokenPage,
......@@ -47,10 +46,10 @@ from import create_french_liquidity
from .netfinca_browser import NetfincaBrowser
__all__ = ['CragrAPI']
__all__ = ['CreditAgricoleBrowser']
class CragrAPI(LoginBrowser):
class CreditAgricoleBrowser(LoginBrowser):
login_page = URL(r'particulier/acceder-a-mes-comptes.html$', LoginPage)
keypad = URL(r'particulier/acceder-a-mes-comptes.authenticationKeypad.json', KeypadPage)
security_check = URL(r'particulier/acceder-a-mes-comptes.html/j_security_check', SecurityPage)
......@@ -119,10 +118,9 @@ class CragrAPI(LoginBrowser):
'(?P<space>.*)/operations/(?P<op>.*)/virement/jcr:content.transfer-data.json\?useSession=true', TransferPage
transfer_exec = URL('(?P<space>.*)/operations/(?P<op>.*)/virement/jcr:content.process-transfer.json', TransferPage)
old_website = URL(r'https://.*particuliers.html$', OldWebsitePage)
def __init__(self, website, *args, **kwargs):
super(CragrAPI, self).__init__(*args, **kwargs)
super(CreditAgricoleBrowser, self).__init__(*args, **kwargs) = website
self.accounts_url = None
......@@ -138,7 +136,7 @@ class CragrAPI(LoginBrowser):
return self.session.cookies.get('marche', None)
def deinit(self):
super(CragrAPI, self).deinit()
super(CreditAgricoleBrowser, self).deinit()
......@@ -179,17 +177,13 @@ class CragrAPI(LoginBrowser):
if not self.username or not self.password:
raise BrowserIncorrectPassword()
# First we try to connect to the new website: if the connection
# is on the old website, we will automatically redirected.
website ='.fr', '')
region_domain = re.sub(r'^www\.', '', website)
# For historical reasons (old cragr website), the websites look like '',
# from which we extract 'ca-region' to construct the BASEURL with a format such as:
# ''
region_domain = re.sub(r'^www\.', '','.fr', ''))
self.BASEURL = 'https://%s/' % region_domain
if self.old_website.is_here():
self.BASEURL = 'https://%s/' %
self.logger.warning('This is a regional connection, switching to old website with URL %s', self.BASEURL)
raise SiteSwitch('region')
# accounts_url may contain '/particulier', '/professionnel', '/entreprise', '/agriculteur' or '/association'
......@@ -177,6 +177,8 @@ ACCOUNT_TYPES = {
'CB': Account.TYPE_SAVINGS, # Carré bleu / PEL
'BOOSTE4': Account.TYPE_SAVINGS, # Livret d'Epargne Forteo
'PEPS': Account.TYPE_SAVINGS, # Plan d'Epargne Populaire
......@@ -731,7 +733,3 @@ class ProfileDetailsPage(LoggedPage, HTMLPage):
class ProProfileDetailsPage(ProfileDetailsPage):
class OldWebsitePage(HTMLPage):
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