diff --git a/modules/societegenerale/browser.py b/modules/societegenerale/browser.py index e6b600a15c6d02273c2716ebc91c2fbeeb12157a..0dc676854724e2cbd6c6de3f06b6e9aad56da1b3 100644 --- a/modules/societegenerale/browser.py +++ b/modules/societegenerale/browser.py @@ -34,7 +34,7 @@ from .pages.accounts_list import ( AccountsMainPage, AccountDetailsPage, AccountsPage, LoansPage, HistoryPage, CardHistoryPage, PeaLiquidityPage, AccountsSynthesesPage, - AdvisorPage, HTMLProfilePage, CreditPage, CreditHistoryPage, + AdvisorPage, HTMLProfilePage, CreditPage, CreditHistoryPage, OldHistoryPage, MarketPage, LifeInsurance, LifeInsuranceHistory, LifeInsuranceInvest, LifeInsuranceInvest2, UnavailableServicePage, ) @@ -57,10 +57,15 @@ class SocieteGenerale(LoginBrowser, StatesMixin): accounts = URL(r'/icd/cbo/data/liste-prestations-navigation-authsec.json', AccountsPage) accounts_syntheses = URL(r'/icd/cbo/data/liste-prestations-authsec.json\?n10_avecMontant=1', AccountsSynthesesPage) history = URL(r'/icd/cbo/data/liste-operations-authsec.json', HistoryPage) - card_history = URL(r'/restitution/cns_listeReleveCarteDd.xml', CardHistoryPage) loans = URL(r'/abm/restit/listeRestitutionPretsNET.json\?a100_isPretConso=(?P\w+)', LoansPage) + + card_history = URL(r'/restitution/cns_listeReleveCarteDd.xml', CardHistoryPage) credit = URL(r'/restitution/cns_detailAVPAT.html', CreditPage) credit_history = URL(r'/restitution/cns_listeEcrCav.xml', CreditHistoryPage) + old_hist_page = URL(r'/restitution/cns_detailPep.html', + r'/restitution/cns_listeEcrPep.html', + r'/restitution/cns_detailAlterna.html', + r'/restitution/cns_listeEncoursAlterna.html', OldHistoryPage) # Recipient add_recipient = URL(r'/personnalisation/per_cptBen_ajouterFrBic.html', @@ -223,28 +228,22 @@ def iter_history(self, account): if not account._internal_id: raise BrowserUnavailable() - if account.type in (account.TYPE_LIFE_INSURANCE, account.TYPE_PERP, ): - # request to get json is not available yet, old request to get html response + # get history for account on old website + # request to get json is not available yet, old request to get html response + if any(( + account.type in (account.TYPE_LIFE_INSURANCE, account.TYPE_PERP), + account.type == account.TYPE_REVOLVING_CREDIT and account._loan_type != 'PR_CONSO', + account.type in (account.TYPE_REVOLVING_CREDIT, account.TYPE_SAVINGS) and not account._is_json_histo + )): self.account_details_page.go(params={'idprest': account._prestation_id}) - link = self.page.get_history_link() - if link: - self.location(self.absurl(link)) - for tr in self.page.iter_li_history(): - yield tr - return + history_url = self.page.get_history_url() + assert history_url + self.location(self.absurl(history_url)) - if account.type == account.TYPE_REVOLVING_CREDIT and account._loan_type != 'PR_CONSO': - # request to get json is not available yet, old request to get html response - self.account_details_page.go(params={'idprest': account._prestation_id}) - self.page.go_history_page() - for tr in self.page.iter_credit_history(): + for tr in self.page.iter_history(): yield tr return - if account.type == account.TYPE_REVOLVING_CREDIT and not account._is_json_histo: - # Waiting for account with transactions - return - if account.type == account.TYPE_CARD: self.history.go(params={'b64e200_prestationIdTechnique': account.parent._internal_id}) for summary_card_tr in self.page.iter_card_transactions(card_number=account.number): @@ -269,6 +268,10 @@ def iter_coming(self, account): if not account._internal_id: raise BrowserUnavailable() + if account.type == account.TYPE_SAVINGS and not account._is_json_histo: + # Waiting for account with transactions + return + internal_id = account._internal_id if account.type == account.TYPE_CARD: internal_id = account.parent._internal_id diff --git a/modules/societegenerale/pages/accounts_list.py b/modules/societegenerale/pages/accounts_list.py index 7084b917f4189032633d6ce8e62b2072d56aecb5..e9166f8156b446c9e45c048b3a9fbcdb959ed179 100644 --- a/modules/societegenerale/pages/accounts_list.py +++ b/modules/societegenerale/pages/accounts_list.py @@ -121,7 +121,7 @@ class iter_accounts(DictElement): class item(ItemElement): def condition(self): - return not Dict('etatPrestation')(self) == 'INDISPONIBLE' + return Dict('etatPrestation')(self) != 'INDISPONIBLE' klass = Account @@ -138,6 +138,7 @@ def condition(self): 'COMPTE_SUR_LIVRET': Account.TYPE_SAVINGS, 'LIVRET_EPARGNE_PLUS': Account.TYPE_SAVINGS, 'PLAN_EPARGNE_BANCAIRE': Account.TYPE_SAVINGS, + 'PLAN_EPARGNE_POPULAIRE': Account.TYPE_SAVINGS, 'LIVRET_EPARGNE_POPULAIRE': Account.TYPE_SAVINGS, 'BANQUE_FRANCAISE_MUTUALISEE': Account.TYPE_SAVINGS, 'PRET_GENERAL': Account.TYPE_LOAN, @@ -189,6 +190,10 @@ def obj__is_json_histo(self): if Field('type')(self) == Account.TYPE_REVOLVING_CREDIT and \ not Dict('produit')(self) in ('COMPTE_ALTERNA', 'AVANCE_PATRIMOINE'): return True + # PLAN_EPARGNE_POPULAIRE account type history is not in json yet + if Field('type')(self) == Account.TYPE_SAVINGS and \ + not Dict('produit')(self) in ('PLAN_EPARGNE_POPULAIRE', ): + return True class AccountsSynthesesPage(JsonBasePage): def is_new_website_available(self): @@ -501,11 +506,11 @@ def obj_raw(self): class CreditPage(LoggedPage, HTMLPage): - def go_history_page(self): + def get_history_url(self): redirection_script = CleanText('//script[contains(text(), "setPrestationURL")]')(self.doc) history_link = re.search(r'setPrestationURL\("(.*)"\)', redirection_script) if history_link: - self.browser.location(self.browser.absurl(history_link.group(1))) + return history_link.group(1) class CreditHistoryPage(LoggedPage, HTMLPage): @@ -516,7 +521,7 @@ def build_doc(self, content): return super(CreditHistoryPage, self).build_doc(content) @method - class iter_credit_history(ListElement): + class iter_history(ListElement): item_xpath = '//tr' class item(ItemElement): @@ -532,6 +537,24 @@ def obj_amount(self): return MyDecimal(CleanText('./td[contains(@headers, "Debit")]', replace=[(' ', '')]))(self) +class OldHistoryPage(LoggedPage, HTMLPage): + def get_history_url(self): + redirection = CleanText('//body/@onload')(self.doc) + history_link = re.search(r",'(/.*)',", redirection) + if history_link: + return history_link.group(1) + + def iter_history(self): + is_no_transaction_msg = any(( + self.doc.xpath(u'//div[contains(text(), "Aucune opération trouvée sur la période de restitution possible")]'), + self.doc.xpath(u'//div[contains(text(), "Aucune opération n\'a été réalisée depuis le dernier relevé")]'), + )) + assert is_no_transaction_msg, 'There are transactions, retrieve them !' + + # waiting for account with history + return [] + + class LifeInsurance(LoggedPage, HTMLPage): def on_load(self): errors_msg = ( @@ -549,8 +572,9 @@ def on_load(self): def has_link(self): return Link('//a[@href="asvcns20a.html"]', default=NotAvailable)(self.doc) - def get_history_link(self): - return Link('//a[img[@alt="Suivi des opérations"]]', default=NotAvailable)(self.doc) + def get_history_url(self): + history_url = Link('//a[img[@alt="Suivi des opérations"]]', default=NotAvailable)(self.doc) + return history_url def get_pages(self): pages = CleanText('//div[@class="net2g_asv_tableau_pager"]')(self.doc) @@ -625,7 +649,7 @@ class item(ItemElement): class LifeInsuranceHistory(LifeInsurance): @pagination @method - class iter_li_history(TableElement): + class iter_history(TableElement): def next_page(self): return self.page.li_pagination()