diff --git a/weboob/backends/creditmutuel/backend.py b/weboob/backends/creditmutuel/backend.py index c5a472a8..296e8ab8 100644 --- a/weboob/backends/creditmutuel/backend.py +++ b/weboob/backends/creditmutuel/backend.py @@ -59,5 +59,5 @@ class CreditMutuelBackend(BaseBackend, ICapBank): return iter([]) def iter_history(self, account): - """ TODO Not supported yet """ - return iter([]) + for history in self.browser.get_history(account): + yield history diff --git a/weboob/backends/creditmutuel/browser.py b/weboob/backends/creditmutuel/browser.py index 366a6ec9..4a15c686 100644 --- a/weboob/backends/creditmutuel/browser.py +++ b/weboob/backends/creditmutuel/browser.py @@ -18,7 +18,7 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword -from .pages import LoginPage, LoginErrorPage, AccountsPage +from .pages import LoginPage, LoginErrorPage, AccountsPage, OperationsPage __all__ = ['CreditMutuelBrowser'] @@ -32,7 +32,8 @@ class CreditMutuelBrowser(BaseBrowser): USER_AGENT = BaseBrowser.USER_AGENTS['wget'] PAGES = {'https://www.creditmutuel.fr/groupe/fr/index.html': LoginPage, 'https://www.creditmutuel.fr/groupe/fr/identification/default.cgi': LoginErrorPage, - 'https://www.creditmutuel.fr/cmdv/fr/banque/situation_financiere.cgi': AccountsPage + 'https://www.creditmutuel.fr/cmdv/fr/banque/situation_financiere.cgi': AccountsPage, + 'https://www.creditmutuel.fr/cmdv/fr/banque/mouvements.cgi.*' : OperationsPage } def __init__(self, *args, **kwargs): @@ -68,6 +69,19 @@ class CreditMutuelBrowser(BaseBrowser): return None + def get_history(self, account): + page_url = account.link_id + #operations_count = 0 + while (page_url): + self.location('https://%s/cmdv/fr/banque/%s' % (self.DOMAIN, page_url)) + #for page_operation in self.page.get_history(operations_count): + # operations_count += 1 + # yield page_operation + for op in self.page.get_history(): + yield op + page_url = self.page.next_page_url() + + #def get_coming_operations(self, account): # if not self.is_on_page(AccountComing) or self.page.account.id != account.id: # self.location('/NS_AVEEC?ch4=%s' % account.link_id) diff --git a/weboob/backends/creditmutuel/pages.py b/weboob/backends/creditmutuel/pages.py index 9534b70f..d7004caf 100644 --- a/weboob/backends/creditmutuel/pages.py +++ b/weboob/backends/creditmutuel/pages.py @@ -18,6 +18,7 @@ from weboob.tools.browser import BasePage from weboob.capabilities.bank import Account +from weboob.capabilities.bank import Operation class LoginPage(BasePage): def login(self, login, passwd): @@ -51,3 +52,38 @@ class AccountsPage(BasePage): l.append(account) #raise NotImplementedError() return l + + def next_page_url(self): + """ TODO pouvoir passer à la page des comptes suivante """ + return 0 + +class OperationsPage(BasePage): + def get_history(self): + index = 0 + for tr in self.document.getiterator('tr'): + first_td = tr.getchildren()[0] + if first_td.attrib.get('class', '') == 'i g' or first_td.attrib.get('class', '') == 'p g': + operation = Operation(index) + index += 1 + operation.date = first_td.text + operation.label = tr.getchildren()[2].text.replace('\n',' ') + if len(tr.getchildren()[3].text) > 2: + s = tr.getchildren()[3].text + elif len(tr.getchildren()[4].text) > 2: + s = tr.getchildren()[4].text + else: + s = "0" + print "s"+s+"::"+operation.label+"::" + balance = u'' + for c in s: + if c.isdigit() or c == "-": + balance += c + if c == ',': + balance += '.' + operation.amount = float(balance) + yield operation + + def next_page_url(self): + """ TODO pouvoir passer à la page des opérations suivantes """ + return 0 +