diff --git a/modules/oney/browser.py b/modules/oney/browser.py index 15db5e63789fb5e78a8a8b25d2af8f1b0e6f8f4f..a7f5ee4f532146e391507887673803ffd31f97cb 100644 --- a/modules/oney/browser.py +++ b/modules/oney/browser.py @@ -17,7 +17,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with this weboob module. If not, see . -from datetime import date +from datetime import date, timedelta +from dateutil.relativedelta import relativedelta +from itertools import chain from weboob.exceptions import BrowserIncorrectPassword from weboob.browser import LoginBrowser, URL, need_login @@ -107,15 +109,29 @@ def get_accounts_list(self): return accounts - def _build_hist_form(self): + def _build_hist_form(self, last_months=False): form = {} d = date.today() - form['jourDebut'] = '1' - form['moisDebut'] = '1' - form['anneeDebut'] = '2016' - form['jourFin'] = str(d.day) - form['moisFin'] = str(d.month) - form['anneeFin'] = str(d.year) + + if not last_months: + # before the last two months + end = d.replace(day=1) + relativedelta(months=-1, days=-1) + form['jourDebut'] = '1' + form['moisDebut'] = '1' + form['anneeDebut'] = '2016' + form['jourFin'] = str(end.day) + form['moisFin'] = str(end.month) + form['anneeFin'] = str(end.year) + else: + # the last two months + start = d.replace(day=1) - timedelta(days=1) + form['jourDebut'] = '1' + form['moisDebut'] = str(start.month) + form['anneeDebut'] = str(start.year) + form['jourFin'] = str(d.day) + form['moisFin'] = str(d.month) + form['anneeFin'] = str(d.year) + form['typeOpe'] = 'deux' form['formatFichier'] = 'xls' # or pdf... great choice return form @@ -134,9 +150,17 @@ def iter_history(self, account): elif account._site == 'other': if self.last_hist.go().has_transactions(): - self.credit_hist.go(params=self._build_hist_form()) - d = date.today().replace(day=1) # TODO is it the right date? - for tr in self.page.iter_history(): + # transactions are missing from the xls from 2016 to today + # so two requests are needed + d = date.today() + page_before = self.credit_hist.open( + params=self._build_hist_form(last_months=True) + ) + page_today = self.credit_hist.go( + params=self._build_hist_form() + ) + + for tr in chain(page_before.iter_history(), page_today.iter_history()): if new_date(tr.date) < d: yield tr