Commit 460a5e55 authored by Guillaume Risbourg's avatar Guillaume Risbourg Committed by Vincent A

[sogecartenet] Added transactions on multiple months

By default the website returns only the transactions of the current
month, but we can choose which month we want in the URL of the CSV
document. So now we go get every transactions in the past until we get
empty datas for 3 months in a row (the website doesn't stop us when
there is no more data in the past, so we have to manually stop asking
for datas).

Closes: 13025@zendesk 8640@zendesk
parent 635c6a06
......@@ -18,7 +18,11 @@
# along with this weboob module. If not, see <>.
from dateutil.parser import parse as parse_date
from dateutil.relativedelta import relativedelta
from weboob.browser import LoginBrowser, URL, need_login
from import urlparse, parse_qs, urlencode, urlunparse
from .pages import LoginPage, AccountsPage, TransactionsPage, PassModificationPage
......@@ -31,6 +35,9 @@ class SogecartesBrowser(LoginBrowser):
accounts = URL('/internationalisation/gestionParcCartes', AccountsPage)
transactions = URL('/internationalisation/csv/operationsParCarte.*', TransactionsPage)
def load_state(self, state):
......@@ -53,7 +60,34 @@ class SogecartesBrowser(LoginBrowser):
def get_history(self, account):
if not account._url:
return ([])
assert self.transactions.is_here()
url = account._url
months_without_data = 0
total_months = 0
# If it makes more than 3 months that we get empty data or if it makes more than 48 months
# that we are gathering transactions we stop asking for transactions (the 48 months limit is
# just to avoid infinite loops)
while months_without_data < self.EMPTY_MONTHS_LIMIT_TRANSACTIONS and total_months < self.MAX_MONTHS_TRANSACTIONS:
assert self.transactions.is_here()
months_without_data = 0
for tr in
yield tr
months_without_data += 1
# We change the end of the url by the previous month
# URL is like this :
# Format of the date in the URL is : YYYY-MM-DD
parts = urlparse(url)
qs = parse_qs(parts.query)
tr_date = parse_date(qs['DATEARR'][0], yearfirst=True) - relativedelta(months=1)
qs['DATEARR'] =
url = urlunparse(
query=urlencode(qs, doseq=True)
total_months += 1
......@@ -95,6 +95,10 @@ class TransactionsPage(SogeLoggedPage, CsvPage):
ENCODING = 'iso_8859_1'
FMTPARAMS = {'delimiter':';'}
def has_data(self):
return not Dict('processing date')(self.doc[0]) == u'No data found'
class get_history(DictElement):
class item(ItemElement):
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