use datetime.date objects and transform coming labels

This commit is contained in:
Romain Bignon 2010-12-27 18:28:24 +01:00
commit 0278af175f
3 changed files with 25 additions and 8 deletions

View file

@ -16,6 +16,9 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
from datetime import date
from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Operation
@ -24,6 +27,12 @@ __all__ = ['AccountComing']
class AccountComing(BasePage):
LABEL_PATTERNS = [('^FACTURECARTEDU(?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2})(?P<text>.*)',
u'CB %(yy)s-%(mm)s-%(dd)s: %(text)s'),
('^PRELEVEMENT(?P<text>.*)', 'Order: %(text)s'),
('^ECHEANCEPRET(?P<text>.*)', u'Loan payment n°%(text)s'),
]
def on_loaded(self):
self.operations = []
@ -32,7 +41,8 @@ class AccountComing(BasePage):
tds = tr.findall('td')
if len(tds) != 3:
continue
date = tds[0].getchildren()[0].attrib.get('name', '')
d = tds[0].getchildren()[0].attrib.get('name', '')
d = date(int(d[0:4]), int(d[4:6]), int(d[6:8]))
label = u''
label += tds[1].text or u''
label = label.replace(u'\xa0', u'')
@ -41,10 +51,16 @@ class AccountComing(BasePage):
if child.tail: label += child.tail
if tds[1].tail: label += tds[1].tail
label = label.strip()
for pattern, text in self.LABEL_PATTERNS:
m = re.match(pattern, label)
if m:
label = text % m.groupdict()
amount = tds[2].text.replace('.', '').replace(',', '.')
operation = Operation(len(self.operations))
operation.date = date
operation.date = d
operation.label = label
operation.amount = float(amount)
self.operations.append(operation)

View file

@ -16,6 +16,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from datetime import date
from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Operation
@ -32,8 +34,7 @@ class AccountHistory(BasePage):
tds = tr.findall('td')
if len(tds) != 4:
continue
date = u''
date = tds[0].text
d = date(*reversed([int(x) for x in tds[0].text.split('/')]))
label = u''
label += tds[1].text
label = label.replace(u'\xa0', u'')
@ -51,7 +52,7 @@ class AccountHistory(BasePage):
else:
operation.amount = - float(amount)
operation.date = date
operation.date = d
operation.label = label
self.operations.append(operation)

View file

@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from datetime import datetime
from datetime import datetime, date
from .base import IBaseCap, CapBaseObject
@ -48,7 +48,7 @@ class Account(CapBaseObject):
class Operation(CapBaseObject):
def __init__(self, id):
CapBaseObject.__init__(self, id)
self.add_field('date', (basestring,datetime))
self.add_field('date', (basestring,datetime,date))
self.add_field('label', unicode)
self.add_field('amount', float)
@ -59,7 +59,7 @@ class Transfer(CapBaseObject):
def __init__(self, id):
CapBaseObject.__init__(self, id)
self.add_field('amount', float)
self.add_field('date', (basestring,datetime))
self.add_field('date', (basestring,datetime,date))
self.add_field('origin', (int,long,basestring))
self.add_field('recipient', (int,long,basestring))