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