Commit 3e29f496 authored by Julien Montagnat's avatar Julien Montagnat Committed by Vincent A

[carrefourbanque] New implementation of CardHistoryPageJSON

The pagination of the current CardHistoryPage is not working anymore.
To get more transactions we need to use a JSON API.
The POST method need a date_recup value which is a non-determinable timestamp that we get in the html of the CardHistoryPage.
Everytime we call the JSON API, we get, the transactions of the previous calls, 40 new transactions and a new date_recup that we can use to do a new request.
parent 0c8540c6
Pipeline #3291 passed with stages
in 17 minutes and 5 seconds
......@@ -28,7 +28,7 @@ from import basestring
from .pages import (
LoginPage, MaintenancePage, HomePage, IncapsulaResourcePage, LoanHistoryPage, CardHistoryPage, SavingHistoryPage,
LifeInvestmentsPage, LifeHistoryPage
LifeInvestmentsPage, LifeHistoryPage, CardHistoryJsonPage,
......@@ -50,7 +50,9 @@ class CarrefourBanqueBrowser(LoginBrowser, StatesMixin):
card_history = URL(r'/espace-client/carte-credit/solde-dernieres-operations\?(.*)', CardHistoryPage)
card_history_json = URL(r'/espace-client/carte-credit/consultation_solde_ajax', CardHistoryJsonPage)
life_history = URL(r'/espace-client/assurance-vie/historique-des-operations\?(.*)', LifeHistoryPage)
life_investments = URL(r'/espace-client/assurance-vie/solde-dernieres-operations\?(.*)', LifeInvestmentsPage)
......@@ -153,7 +155,6 @@ class CarrefourBanqueBrowser(LoginBrowser, StatesMixin):
def iter_history(self, account):
......@@ -161,11 +162,39 @@ class CarrefourBanqueBrowser(LoginBrowser, StatesMixin):
assert self.saving_history.is_here()
elif account.type == Account.TYPE_CARD:
assert self.card_history.is_here()
previous_date =
if previous_date:
total = 0
loop_limit = 500
for page in range(loop_limit):
self.card_history_json.go(data={'dateRecup': previous_date, 'index': 0})
previous_date =
it = iter(
for _ in range(total):
# those transactions were returned on previous pages
for tr in it:
total += 1
yield tr
if not previous_date:
# last page
"End of loop after %s iterations but still got a next page, it will miss some transactions",
elif account.type == Account.TYPE_LOAN:
assert self.loan_history.is_here()
elif account.type == Account.TYPE_LIFE_INSURANCE:
assert self.life_history.is_here()
raise NotImplementedError()
for tr in
yield tr
......@@ -25,12 +25,13 @@ from io import BytesIO
from PIL import Image
from import json
from weboob.browser.pages import HTMLPage, LoggedPage, pagination
from weboob.browser.elements import ListElement, TableElement, ItemElement, method
from weboob.browser.pages import HTMLPage, LoggedPage, pagination, JsonPage
from weboob.browser.elements import ListElement, TableElement, ItemElement, method, DictElement
from weboob.browser.filters.standard import (
Regexp, Field, CleanText, CleanDecimal, Eval, Currency
Regexp, Field, CleanText, CleanDecimal, Eval, Currency, Date,
from weboob.browser.filters.html import Link, TableCell, Attr, AttributeNotFound
from weboob.browser.filters.json import Dict
from import Account
from weboob.capabilities.wealth import Investment
from weboob.capabilities.base import NotAvailable
......@@ -221,7 +222,6 @@ class iter_history_generic(Transaction.TransactionsElement):
def obj_type(self):
if len(self.el.xpath('./td')) <= 3:
return Transaction.TYPE_BANK
col = TableCell('debittype', default=None)
if col(self):
debittype = CleanText(col)(self)
......@@ -333,4 +333,29 @@ class LoanHistoryPage(TransactionsPage):
class CardHistoryPage(TransactionsPage):
def get_previous_date(self):
return Attr('//a[@id="op_precedente"]', 'date_recup', default=None)(self.doc)
class CardHistoryJsonPage(LoggedPage, JsonPage):
def get_previous_date(self):
return Dict('str_datePrecedente', default=None)(self.doc)
class iter_history(DictElement):
item_xpath = 'tab_historique'
class item(ItemElement):
klass = Transaction
obj_date = Date(CleanText(Dict('date')), dayfirst=True)
obj_raw = CleanText(Dict('label'))
obj_amount = CleanDecimal.French(Dict('amount'))
def obj_type(self):
debittype = Dict('mode')
if debittype(self) == 'Différé':
return Transaction.TYPE_DEFERRED_CARD
return Transaction.TYPE_CARD
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