apply changes to ICapBank API

This commit is contained in:
Romain Bignon 2012-02-26 18:30:06 +01:00
commit be14595308
10 changed files with 60 additions and 43 deletions

View file

@ -50,13 +50,13 @@ class TransactionsBasePage(BasePage):
def parse_text(self, op): def parse_text(self, op):
op.category = NotAvailable op.category = NotAvailable
if ' ' in op.text: if ' ' in op.raw:
op.category, useless, op.label = [part.strip() for part in op.label.partition(' ')] op.category, useless, op.label = [part.strip() for part in op.label.partition(' ')]
else: else:
op.label = op.text op.label = op.raw
for pattern, _type, _label in self.LABEL_PATTERNS: for pattern, _type, _label in self.LABEL_PATTERNS:
m = pattern.match(op.text) m = pattern.match(op.raw)
if m: if m:
op.type = _type op.type = _type
op.label = (_label % m.groupdict()).strip() op.label = (_label % m.groupdict()).strip()
@ -70,7 +70,7 @@ class AccountHistory(TransactionsBasePage):
id = tr.find('td').find('input').attrib['value'] id = tr.find('td').find('input').attrib['value']
op = Transaction(id) op = Transaction(id)
op.text = tr.findall('td')[2].text.replace(u'\xa0', u'').strip() op.raw = tr.findall('td')[2].text.replace(u'\xa0', u'').strip()
op.date = date(*reversed([int(x) for x in tr.findall('td')[1].text.split('/')])) op.date = date(*reversed([int(x) for x in tr.findall('td')[1].text.split('/')]))
self.parse_text(op) self.parse_text(op)
@ -105,7 +105,7 @@ class AccountComing(TransactionsBasePage):
i += 1 i += 1
operation = Transaction(i) operation = Transaction(i)
operation.date = d operation.date = d
operation.text = text.strip() operation.raw = text.strip()
self.parse_text(operation) self.parse_text(operation)
operation.amount = float(amount) operation.amount = float(amount)
yield operation yield operation

View file

@ -22,7 +22,7 @@
from datetime import date from datetime import date
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Transaction
__all__ = ['AccountHistory'] __all__ = ['AccountHistory']
@ -56,7 +56,7 @@ class AccountHistory(BasePage):
amount = amount.strip(u' \n\t\x80').replace(' ', '').replace(',', '.') amount = amount.strip(u' \n\t\x80').replace(' ', '').replace(',', '.')
# if we don't have exactly one '.', this is not a floatm try the next # if we don't have exactly one '.', this is not a floatm try the next
operation = Operation(len(self.operations)) operation = Transaction(len(self.operations))
operation.amount = float(amount) operation.amount = float(amount)
operation.date = d operation.date = d

View file

@ -20,7 +20,7 @@
import re import re
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Transaction
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
@ -36,10 +36,10 @@ class AccountHistory(BasePage):
operations = [] operations = []
for mvt in mvt_ligne: for mvt in mvt_ligne:
operation = Operation(len(operations)) operation = Transaction(len(operations))
operation.date = mvt.xpath("./td/span")[0].text operation.date = mvt.xpath("./td/span")[0].text
tmp = mvt.xpath("./td/span")[1] tmp = mvt.xpath("./td/span")[1]
operation.label = unicode(self.parser.tocleanstring(tmp)) operation.raw = unicode(self.parser.tocleanstring(tmp))
r = re.compile(r'\d+') r = re.compile(r'\d+')

View file

@ -19,7 +19,7 @@
from weboob.capabilities.bank import ICapBank, AccountNotFound from weboob.capabilities.bank import ICapBank, AccountNotFound
from weboob.capabilities.bank import Account, Operation from weboob.capabilities.bank import Account, Transaction
from weboob.tools.backend import BaseBackend, BackendConfig from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.tools.value import ValueBackendPassword from weboob.tools.value import ValueBackendPassword
from weboob.capabilities.base import NotAvailable from weboob.capabilities.base import NotAvailable
@ -201,7 +201,7 @@ class CmbBackend(BaseBackend, ICapBank):
for tr in table.getiterator('tr'): for tr in table.getiterator('tr'):
if (tr.get('class') != 'LnTit' and if (tr.get('class') != 'LnTit' and
tr.get('class') != 'LnTot'): tr.get('class') != 'LnTot'):
operation = Operation(i) operation = Transaction(i)
td = tr.xpath('td') td = tr.xpath('td')
div = td[1].xpath('div') div = td[1].xpath('div')
@ -210,7 +210,7 @@ class CmbBackend(BaseBackend, ICapBank):
div = td[2].xpath('div') div = td[2].xpath('div')
label = div[0].xpath('a')[0].text.replace('\n','') label = div[0].xpath('a')[0].text.replace('\n','')
operation.label = unicode(' '.join(label.split())) operation.raw = unicode(' '.join(label.split()))
amount = td[3].text amount = td[3].text
if amount.count(',') != 1: if amount.count(',') != 1:

View file

@ -21,7 +21,7 @@
import re import re
from weboob.capabilities.bank import Account from weboob.capabilities.bank import Account
from .base import CragrBasePage from .base import CragrBasePage
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Transaction
def clean_amount(amount): def clean_amount(amount):
""" """
@ -187,7 +187,7 @@ class AccountsList(CragrBasePage):
Returns the history of a specific account. Note that this function Returns the history of a specific account. Note that this function
expects the current page to be the one dedicated to this history. expects the current page to be the one dedicated to this history.
start_index is the id used for the first created operation. start_index is the id used for the first created operation.
start_offset allows ignoring the `n' first Operations on the page. start_offset allows ignoring the `n' first Transactions on the page.
""" """
# tested on CA Lorraine, Paris, Toulouse # tested on CA Lorraine, Paris, Toulouse
# avoir parsing the page as an account-dedicated page if it is not the case # avoir parsing the page as an account-dedicated page if it is not the case
@ -244,10 +244,10 @@ class AccountsList(CragrBasePage):
if skipped < start_offset: if skipped < start_offset:
skipped += 1 skipped += 1
continue continue
operation = Operation(index) operation = Transaction(index)
index += 1 index += 1
operation.date = self.extract_text(line[0]) operation.date = self.extract_text(line[0])
operation.label = self.extract_text(line[1]) operation.raw = self.extract_text(line[1])
operation.amount = clean_amount(self.extract_text(line[2])) operation.amount = clean_amount(self.extract_text(line[2]))
yield operation yield operation
elif (not alternate_layout): elif (not alternate_layout):
@ -264,20 +264,20 @@ class AccountsList(CragrBasePage):
# this is the first line of an operation entry, displaying the date and label # this is the first line of an operation entry, displaying the date and label
data = self.extract_text(body_elmt) data = self.extract_text(body_elmt)
matches = re.findall('^([012][0-9]|3[01])/(0[1-9]|1[012]).(.+)$', data) matches = re.findall('^([012][0-9]|3[01])/(0[1-9]|1[012]).(.+)$', data)
operation = Operation(index) operation = Transaction(index)
index += 1 index += 1
if (matches): if (matches):
operation.date = u'%s/%s' % (matches[0][0], matches[0][1]) operation.date = u'%s/%s' % (matches[0][0], matches[0][1])
operation.label = u'%s' % matches[0][2] operation.raw = u'%s' % matches[0][2]
else: else:
operation.date = u'01/01' operation.date = u'01/01'
operation.label = u'Unknown' operation.raw = u'Unknown'
else: else:
for i in range(0, len(interesting_divs)/3): for i in range(0, len(interesting_divs)/3):
if skipped < start_offset: if skipped < start_offset:
skipped += 1 skipped += 1
continue continue
operation = Operation(index) operation = Transaction(index)
index += 1 index += 1
# amount # amount
operation.amount = clean_amount(self.extract_text(interesting_divs[(i*3)+1])) operation.amount = clean_amount(self.extract_text(interesting_divs[(i*3)+1]))
@ -288,5 +288,5 @@ class AccountsList(CragrBasePage):
#label #label
data = self.extract_text(interesting_divs[(i*3)+2]) data = self.extract_text(interesting_divs[(i*3)+2])
data = re.sub(' +', ' ', data) data = re.sub(' +', ' ', data)
operation.label = u'%s' % data operation.raw = u'%s' % data
yield operation yield operation

View file

@ -20,7 +20,7 @@
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Account from weboob.capabilities.bank import Account
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Transaction
class LoginPage(BasePage): class LoginPage(BasePage):
def login(self, login, passwd): def login(self, login, passwd):
@ -76,10 +76,10 @@ class OperationsPage(BasePage):
for tr in self.document.getiterator('tr'): for tr in self.document.getiterator('tr'):
first_td = tr.getchildren()[0] first_td = tr.getchildren()[0]
if first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g': if first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g':
operation = Operation(index) operation = Transaction(index)
index += 1 index += 1
operation.date = first_td.text operation.date = first_td.text
operation.label = u"%s"%tr.getchildren()[2].text.replace('\n',' ') operation.raw = u"%s"%tr.getchildren()[2].text.replace('\n',' ')
if len(tr.getchildren()[3].text) > 2: if len(tr.getchildren()[3].text) > 2:
s = tr.getchildren()[3].text s = tr.getchildren()[3].text
elif len(tr.getchildren()[4].text) > 2: elif len(tr.getchildren()[4].text) > 2:

View file

@ -22,7 +22,7 @@ import re
from datetime import date from datetime import date
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Account, Operation from weboob.capabilities.bank import Account, Transaction
from weboob.capabilities.base import NotAvailable from weboob.capabilities.base import NotAvailable
@ -52,14 +52,31 @@ class AccountsListPage(BasePage):
yield account yield account
class HistoryPage(BasePage): class HistoryPage(BasePage):
LABEL_PATTERNS = [(re.compile('^VIR(EMENT)? (?P<text>.*)'), Transaction.TYPE_TRANSFER, '%(text)s'),
(re.compile('^PRLV (?P<text>.*)'), Transaction.TYPE_ORDER, '%(text)s'),
(re.compile('^CB (?P<text>.*)\s+(?P<dd>\d+)/(?P<mm>\d+)\s*(?P<loc>.*)'),
Transaction.TYPE_CARD, '%(mm)s/%(dd)s: %(text)s'),
(re.compile('^DAB (?P<text>.*)'), Transaction.TYPE_WITHDRAWAL, '%(text)s'),
(re.compile('^CHEQUE$'), Transaction.TYPE_CHECK, 'CHEQUE'),
(re.compile('^COTIS\.? (?P<text>.*)'), Transaction.TYPE_BANK, '%(text)s'),
(re.compile('^REMISE (?P<text>.*)'), Transaction.TYPE_DEPOSIT, '%(text)s'),
]
def get_operations(self): def get_operations(self):
for script in self.document.getiterator('script'): for script in self.document.getiterator('script'):
if script.text is None or script.text.find('\nCL(0') < 0: if script.text is None or script.text.find('\nCL(0') < 0:
continue continue
for m in re.finditer(r"CL\((\d+),'(.+)','(.+)','(.+)','([\d -\.,]+)','([\d -\.,]+)','\d+','\d+','[\w\s]+'\);", script.text, flags=re.MULTILINE): for m in re.finditer(r"CL\((\d+),'(.+)','(.+)','(.+)','([\d -\.,]+)','([\d -\.,]+)','\d+','\d+','[\w\s]+'\);", script.text, flags=re.MULTILINE):
op = Operation(m.group(1)) op = Transaction(m.group(1))
op.label = m.group(4) op.raw = m.group(4)
for pattern, _type, _label in self.LABEL_PATTERNS:
mm = pattern.match(op.raw)
if mm:
op.type = _type
op.label = re.sub('[ ]+', ' ', _label % mm.groupdict()).strip()
break
op.amount = float(m.group(5).replace('.','').replace(',','.').replace(' ', '').strip(u' \t\u20ac\xa0\n\r')) op.amount = float(m.group(5).replace('.','').replace(',','.').replace(' ', '').strip(u' \t\u20ac\xa0\n\r'))
op.date = date(*reversed([int(x) for x in m.group(3).split('/')])) op.date = date(*reversed([int(x) for x in m.group(3).split('/')]))
op.category = NotAvailable op.category = NotAvailable

View file

@ -21,7 +21,7 @@
from datetime import date from datetime import date
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Transaction
from weboob.capabilities.base import NotAvailable from weboob.capabilities.base import NotAvailable
__all__ = ['AccountHistoryCC', 'AccountHistoryLA'] __all__ = ['AccountHistoryCC', 'AccountHistoryLA']
@ -36,7 +36,7 @@ class AccountHistoryCC(BasePage):
for tr in table.xpath('tr'): for tr in table.xpath('tr'):
id = i id = i
texte = tr.text_content().split('\n') texte = tr.text_content().split('\n')
op = Operation(id) op = Transaction(id)
op.label = texte[2] op.label = texte[2]
op.date = date(*reversed([int(x) for x in texte[0].split('/')])) op.date = date(*reversed([int(x) for x in texte[0].split('/')]))
op.category = texte[4] op.category = texte[4]
@ -60,10 +60,10 @@ class AccountHistoryLA(BasePage):
for tr in history: for tr in history:
id = i id = i
texte = tr.text_content().strip().split('\n') texte = tr.text_content().strip().split('\n')
op = Operation(id) op = Transaction(id)
# The size is not the same if there are two dates or only one # The size is not the same if there are two dates or only one
length = len(texte) length = len(texte)
op.label = unicode(texte[length - 2].strip()) op.raw = unicode(texte[length - 2].strip())
op.date = date(*reversed([int(x) for x in texte[0].split('/')])) op.date = date(*reversed([int(x) for x in texte[0].split('/')]))
op.category = NotAvailable op.category = NotAvailable

View file

@ -19,7 +19,7 @@
import base64 import base64
from datetime import date from datetime import date
from weboob.capabilities.bank import Operation from weboob.capabilities.bank import Transaction
from weboob.capabilities.bank import Account from weboob.capabilities.bank import Account
from weboob.tools.browser import BasePage, BrowserUnavailable from weboob.tools.browser import BasePage, BrowserUnavailable
from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError
@ -174,7 +174,7 @@ class AccountHistoryPage(BasePage):
if len(tr.findall("th"))!=0 or\ if len(tr.findall("th"))!=0 or\
len(tr.findall("td"))==0: len(tr.findall("td"))==0:
continue continue
operation=Operation(len(operations)) operation=Transaction(len(operations))
mntColumn=0 mntColumn=0
for td in tr.iter('td'): for td in tr.iter('td'):
value=td.attrib.get('id') value=td.attrib.get('id')
@ -184,7 +184,7 @@ class AccountHistoryPage(BasePage):
operation.date=date(*reversed([int(x) for x in td.text.split('/')])) operation.date=date(*reversed([int(x) for x in td.text.split('/')]))
elif value.startswith("lib") or value.startswith("opLib"): elif value.startswith("lib") or value.startswith("opLib"):
# misclosed A tag requires to grab text from td # misclosed A tag requires to grab text from td
operation.label=u''.join([txt.strip() for txt in td.itertext()]) operation.raw=u''.join([txt.strip() for txt in td.itertext()])
elif value.startswith("solde") or value.startswith("mnt"): elif value.startswith("solde") or value.startswith("mnt"):
mntColumn+=1 mntColumn+=1
if td.text.strip() != "": if td.text.strip() != "":

View file

@ -68,7 +68,7 @@ class Transaction(CapBaseObject):
CapBaseObject.__init__(self, id) CapBaseObject.__init__(self, id)
self.add_field('date', (basestring, datetime, date)) self.add_field('date', (basestring, datetime, date))
self.add_field('type', int, self.TYPE_UNKNOWN) self.add_field('type', int, self.TYPE_UNKNOWN)
self.add_field('text', unicode) self.add_field('raw', unicode)
self.add_field('category', unicode) self.add_field('category', unicode)
self.add_field('label', unicode) self.add_field('label', unicode)
self.add_field('amount', float) self.add_field('amount', float)