finish coming

This commit is contained in:
Kevin Pouget 2012-11-16 15:40:43 +01:00 committed by Romain Bignon
commit 2ff8af405d
3 changed files with 80 additions and 40 deletions

View file

@ -31,7 +31,7 @@ __all__ = ['CreditCooperatifBackend']
class CreditCooperatifBackend(BaseBackend, ICapBank):
NAME = 'creditcooperatif'
MAINTAINER = u'Kevin Pouget 1459'
MAINTAINER = u'Kevin Pouget'
EMAIL = 'weboob@kevin.pouget.me'
VERSION = '0.d'
DESCRIPTION = u'Credit Cooperatif French bank website'
@ -61,3 +61,7 @@ class CreditCooperatifBackend(BaseBackend, ICapBank):
def iter_history(self, account):
with self.browser:
return self.browser.get_history(account)
def iter_coming(self, account):
with self.browser:
return self.browser.get_coming(account)

View file

@ -22,7 +22,7 @@ import urllib
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from .pages import LoginPage, AccountsPage, TransactionsPage
from .pages import LoginPage, AccountsPage, TransactionsPage, ComingTransactionsPage
__all__ = ['CreditCooperatif']
@ -34,7 +34,9 @@ class CreditCooperatif(BaseBrowser):
DOMAIN = "www.coopanet.com"
PAGES = {'https://www.coopanet.com/banque/sso/.*': LoginPage,
'https://www.coopanet.com/banque/cpt/incoopanetj2ee.do.*': AccountsPage,
'https://www.coopanet.com/banque/cpt/cpt/situationcomptes.do\?lnkReleveAction=X&numeroExterne=(.*)': TransactionsPage
'https://www.coopanet.com/banque/cpt/cpt/situationcomptes.do\?lnkReleveAction=X&numeroExterne=.*': TransactionsPage,
'https://www.coopanet.com/banque/cpt/cpt/relevecompte.do\?tri_page=.*': TransactionsPage,
'https://www.coopanet.com/banque/cpt/cpt/situationcomptes.do\?lnkOpCB=X&numeroExterne=.*': ComingTransactionsPage
}
def __init__(self, *args, **kwargs):
@ -85,18 +87,25 @@ class CreditCooperatif(BaseBrowser):
return a
return None
def get_history(self, account):
self.location('/banque/cpt/cpt/situationcomptes.do?lnkReleveAction=X&numeroExterne='+ account.id)
while 1:
assert self.is_on_page(TransactionsPage)
for tr in self.page.get_history():
yield tr
next_params = self.page.get_next_params()
if next_params is None:
next_url = self.page.get_next_url()
if next_url is None:
return
self.location(self.buildurl('/cyber/internet/Page.do', **next_params))
self.location(next_url)
def get_coming(self, account):
self.location('/banque/cpt/cpt/situationcomptes.do?lnkOpCB=X&numeroExterne='+ account.id)
assert self.is_on_page(ComingTransactionsPage)
for ctr in self.page.get_history():
yield ctr

View file

@ -27,7 +27,7 @@ from weboob.capabilities.bank import Account
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
__all__ = ['LoginPage', 'AccountsPage']
__all__ = ['LoginPage', 'AccountsPage', 'TransactionsPage', 'ComingTransactionsPage']
class LoginPage(BasePage):
def login(self, login, pin):
@ -74,20 +74,16 @@ class AccountsPage(BasePage):
return
class Transaction(FrenchTransaction):
PATTERNS = [(re.compile('^RET DAB (?P<text>.*?) RETRAIT DU (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}).*'),
FrenchTransaction.TYPE_WITHDRAWAL),
(re.compile('^RET DAB (?P<text>.*?) CARTE ?:.*'),
PATTERNS = [(re.compile('^RETRAIT DAB (?P<text>.*?).*'),
FrenchTransaction.TYPE_WITHDRAWAL),
(re.compile('^(?P<text>.*) RETRAIT DU (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}) .*'),
FrenchTransaction.TYPE_WITHDRAWAL),
(re.compile('(\w+) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}) CB:[^ ]+ (?P<text>.*)'),
FrenchTransaction.TYPE_CARD),
(re.compile('^CARTE \d+ .*'), FrenchTransaction.TYPE_CARD),
(re.compile('^VIR(EMENT)? (?P<text>.*)'), FrenchTransaction.TYPE_TRANSFER),
(re.compile('^PRLV (?P<text>.*)'), FrenchTransaction.TYPE_ORDER),
(re.compile('^CHEQUE.*'), FrenchTransaction.TYPE_CHECK),
(re.compile('^(AGIOS /|FRAIS) (?P<text>.*)'), FrenchTransaction.TYPE_BANK),
(re.compile('^(CONVENTION \d+ )?COTIS(ATION)? (?P<text>.*)'),
FrenchTransaction.TYPE_BANK),
(re.compile('^ABONNEMENT (?P<text>.*)'), FrenchTransaction.TYPE_BANK),
(re.compile('^REMISE (?P<text>.*)'), FrenchTransaction.TYPE_DEPOSIT),
(re.compile('^(?P<text>.*)( \d+)? QUITTANCE .*'),
FrenchTransaction.TYPE_ORDER),
@ -97,43 +93,74 @@ class Transaction(FrenchTransaction):
class TransactionsPage(BasePage):
def get_next_params(self):
if len(self.document.xpath('//li[@id="tbl1_nxt"]')) == 0:
def get_next_url(self):
# can be 'Suivant' or ' Suivant'
next = self.document.xpath("//a[normalize-space(text()) = 'Suivant']")
if not next:
return None
params = {}
for field in self.document.xpath('//input'):
params[field.attrib['name']] = field.attrib.get('value', '')
return next[0].attrib["href"]
params['validationStrategy'] = 'NV'
params['pagingDirection'] = 'NEXT'
params['pagerName'] = 'tbl1'
return params
TRA_ROW_DT_OP = 0
TRA_ROW_DT_VAL = 1
TRA_ROW_NAME = 3
TRA_ROW_DEBIT = 4
TRA_ROW_CREDIT = 5
TR_DATE = 0
TR_TEXT = 2
TR_DEBIT = 3
TR_CREDIT = 4
def get_history(self):
import pdb;pdb.set_trace()
for tr in self.document.xpath('//table[@id="operation"]/tbody/tr'):
tds = tr.findall('td')
def get_content(td):
ret = "".join([ttd.text for ttd in td.xpath(".//td")])
ret = "".join([ttd.text if ttd.text else "" for ttd in td.xpath(".//td")])
return ret.replace(u"\xa0", " ").strip()
date = get_content(tds[0])
raw = get_content(tds[2])
date = get_content(tds[self.TR_DATE])
raw = get_content(tds[self.TR_TEXT])
debit = get_content(tds[3])
credit = get_content(tds[4])
debit = get_content(tds[self.TR_DEBIT])
credit = get_content(tds[self.TR_CREDIT])
t = Transaction(date+""+raw)
t.parse(date, re.sub(r'[ ]+', ' ', raw))
t.set_amount(credit, debit)
yield t
class ComingTransactionsPage(BasePage):
COM_TR_COMMENT = 0
COM_TR_DATE = 1
COM_TR_TEXT = 2
COM_TR_VALUE = 3
def get_history(self):
comment = None
for tr in self.document.xpath('//table[@id="operation"]/tbody/tr'):
tds = tr.findall('td')
def get_content(td):
ret = td.text
return ret.replace(u"\xa0", " ").strip()
raw = get_content(tds[self.COM_TR_TEXT])
if comment is None:
comment = get_content(tds[self.COM_TR_COMMENT])
raw = "%s (%s) " % (raw, comment)
debit = get_content(tds[self.COM_TR_VALUE])
date = get_content(tds[self.COM_TR_DATE])
if comment is not None:
#date is 'JJ/MM'. add '/YYYY'
date += comment[comment.rindex("/"):]
else:
import time
date += "/%d" % time.localtime().tm_year
t = Transaction(date+""+raw)
t.parse(date, re.sub(r'[ ]+', ' ', raw))
t.set_amount("", debit)
yield t
pass