bred: great, the API has been fixed

This commit is contained in:
Romain Bignon 2015-09-09 10:57:53 +02:00 committed by Romain Bignon
commit 3055ea3dd1

View file

@ -18,7 +18,6 @@
# 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 date from datetime import date
from dateutil.relativedelta import relativedelta
from decimal import Decimal from decimal import Decimal
from weboob.capabilities.bank import Account, Transaction from weboob.capabilities.bank import Account, Transaction
@ -104,23 +103,22 @@ class BredBrowser(DomainBrowser):
offset = 0 offset = 0
next_page = True next_page = True
transactions = []
seen = set() seen = set()
while next_page: while next_page:
r = self.api_open('/transactionnel/services/applications/operations/get/%(number)s/%(nature)s/00/%(currency)s/%(startDate)s/%(endDate)s/%(offset)s/%(limit)s' % r = self.api_open('/transactionnel/services/applications/operations/get/%(number)s/%(nature)s/00/%(currency)s/%(startDate)s/%(endDate)s/%(offset)s/%(limit)s' %
{'number': account._number, {'number': account._number,
'nature': account._nature, 'nature': account._nature,
'currency': account.currency, 'currency': account.currency,
'startDate': (date.today() - relativedelta(months=1)).strftime('%Y-%m-%d'), 'startDate': '2000-01-01',
'endDate': date.today().strftime('%Y-%m-%d'), 'endDate': date.today().strftime('%Y-%m-%d'),
'offset': offset, 'offset': offset,
'limit': 50 'limit': 50
}) })
next_page = False next_page = False
offset += 50 offset += 50
transactions = []
for op in reversed(r.json()['content']['operations']): for op in reversed(r.json()['content']['operations']):
# XXX it seems that currently the website returns all transactions at once and doesn't support anymore pagination. next_page = True
#next_page = True
t = Transaction() t = Transaction()
if op['id'] in seen: if op['id'] in seen:
raise ParseError('There are several transactions with the same ID, probably an infinite loop') raise ParseError('There are several transactions with the same ID, probably an infinite loop')
@ -136,5 +134,6 @@ class BredBrowser(DomainBrowser):
t.raw = ' '.join([op['libelle']] + op['details']) t.raw = ' '.join([op['libelle']] + op['details'])
transactions.append(t) transactions.append(t)
# Transactions are unsorted # Transactions are unsorted
return sorted(transactions, key=lambda t: t.rdate, reverse=True) for t in sorted(transactions, key=lambda t: t.rdate, reverse=True):
yield t