Commit e7405716 authored by Célande Adrien's avatar Célande Adrien Committed by Romain Bignon

[societegenerale] iter_documents limits

The security limit is now 30 months.
A new error message can be retrieved when there is no more documents.
Now the documents form only takes a step of 2 months.
parent e6978ad3
......@@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from dateutil.relativedelta import relativedelta
from weboob.browser import LoginBrowser, URL, need_login, StatesMixin
from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, ActionNeeded
......@@ -289,26 +290,14 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
@need_login
def iter_documents(self, subscribtion):
today = datetime.today()
month = today.month
year = today.year
end_date = datetime.today()
# current year
self.bank_statement_search.go()
self.page.post_form(subscribtion, str(month), str(year))
for d in self.page.iter_documents(subscribtion):
yield d
# other years
month = 12
security_limit = 1000
# 5 years since it goes with a 2 months step
security_limit = 30
i = 0
while i < security_limit:
year -= 1
self.bank_statement_search.go()
self.page.post_form(subscribtion, str(month), str(year))
self.page.post_form(subscribtion, end_date)
# No more documents
if self.page.has_error_msg():
......@@ -317,4 +306,7 @@ class SocieteGenerale(LoginBrowser, StatesMixin):
for d in self.page.iter_documents(subscribtion):
yield d
# 3 months step because the documents list is inclusive
# from the 08 to the 06, the 06 statement is included
end_date = end_date - relativedelta(months=+3)
i += 1
......@@ -20,6 +20,7 @@
from __future__ import unicode_literals
import re
from dateutil.relativedelta import relativedelta
from weboob.capabilities.bill import Document, Subscription
from weboob.browser.elements import TableElement, ItemElement, method
......@@ -71,16 +72,17 @@ class BankStatementPage(LoggedPage, BasePage):
# has the same id as the main account it depends on
return 'Points de fidélité' not in Field('label')(self)
def post_form(self, subscription, end_month, year):
def post_form(self, subscription, date):
form = self.get_form(name='abo_rce')
form[subscription._rad_button_id] = 'on'
# from january to the last month
# the last month may be the current one or december
form['rechDebMM'] = '1'
form['rechDebYY'] = year
form['rechFinMM'] = end_month
form['rechFinYY'] = year
# 2 months step
begin = date - relativedelta(months=+2)
form['rechDebMM'] = '%s' % begin.month
form['rechDebYY'] = '%s' % begin.year
form['rechFinMM'] = '%s' % date.month
form['rechFinYY'] = '%s' % date.year
m = re.search(r"surl='src=(.*)&sign=(.*)'", CleanText('//script[contains(text(), "surl")]')(self.doc))
form['src'] = m.group(1)
......@@ -92,11 +94,15 @@ class BankStatementPage(LoggedPage, BasePage):
for a in self.doc.xpath('//a[contains(@href, "pdf")]'):
d = Document()
d.format = 'pdf'
d.label = CleanText('.')(a)
if 'Récapitulatif annuel' in d.label:
continue
date_filter = Regexp(CleanText('.'), r'(\d{2}/\d{2}/\d{4})')
d.date = Date(date_filter, dayfirst=True)(a)
d.format = 'pdf'
d.label = CleanText('.')(a)
d.url = Regexp(Link('.'), r"= '(.*)';")(a)
d.id = '%s_%s' % (subscription.id, date_filter(a).replace('/', ''))
d.type = 'document'
......@@ -104,4 +110,4 @@ class BankStatementPage(LoggedPage, BasePage):
yield d
def has_error_msg(self):
return CleanText('//div[@class="MessageErreur"]')(self.doc)
return CleanText('//div[@class="MessageErreur"]')(self.doc) or CleanText('//span[@class="error_msg"]')(self.doc)
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