diff --git a/modules/fortuneo/browser.py b/modules/fortuneo/browser.py index 1d67cb82..6c7875d0 100644 --- a/modules/fortuneo/browser.py +++ b/modules/fortuneo/browser.py @@ -45,8 +45,7 @@ class Fortuneo(BaseBrowser): def home(self): """main page (login)""" - if not self.is_on_page(AccountHistoryPage): - self.location('/fr/prive/identification.jsp') + self.location('/fr/prive/identification.jsp') def is_logged(self): """Return True if we are logged on website""" diff --git a/modules/fortuneo/pages/accounts_list.py b/modules/fortuneo/pages/accounts_list.py index c31a958b..18005e48 100644 --- a/modules/fortuneo/pages/accounts_list.py +++ b/modules/fortuneo/pages/accounts_list.py @@ -23,7 +23,8 @@ import datetime from weboob.capabilities.bank import Account from weboob.tools.capabilities.bank.transactions import Transaction -from weboob.tools.browser import BasePage #, BrokenPageError +from weboob.tools.browser import BasePage, BrokenPageError +from weboob.capabilities import NotAvailable __all__ = ['AccountsList', 'AccountHistoryPage'] @@ -31,22 +32,24 @@ class AccountHistoryPage(BasePage): def get_operations(self, _id): """history, see http://docs.weboob.org/api/capabilities/bank.html?highlight=transaction#weboob.capabilities.bank.Transaction""" + # TODO need to rewrite that with FrenchTransaction class http://tinyurl.com/6lq4r9t operations = [] tables = self.document.findall(".//*[@id='tabHistoriqueOperations']/tbody/tr") + if len(tables) == 0: + raise BrokenPageError + for i in range(len(tables)): operation = Transaction(len(operations)) date_oper = tables[i].xpath("./td[2]/text()")[0] date_val = tables[i].xpath("./td[3]/text()")[0] label = tables[i].xpath("./td[4]/text()")[0] - label = label.strip() + operation.label = label.strip() amount = tables[i].xpath("./td[5]/text() | ./td[6]/text()") operation.date = datetime.datetime.strptime(date_val, "%d/%m/%Y") operation.rdate = datetime.datetime.strptime(date_oper,"%d/%m/%Y") operation.type = 0 - operation.raw = label - operation.label = u""+label if amount[1] == u'\xa0': amount = amount[0].replace(u"\xa0", "").replace(",", ".").strip() @@ -54,9 +57,7 @@ class AccountHistoryPage(BasePage): amount = amount[1].replace(u"\xa0", "").replace(",", ".").strip() operation.amount = Decimal(amount) - operation.category = u" " # blank category - operation.origin = u" " # blank origin - operation.recipient = u" " # blank rcpt + operation.category = NotAvailable operations.append(operation) @@ -71,14 +72,13 @@ class AccountsList(BasePage): # account.id account.id = cpt.xpath("./td[1]/a/text()")[0] - account.id = str(account.id) - + # account balance account.balance = Decimal(cpt.xpath("./td[3]/text()")[0].replace("EUR", "").replace("\n", "").replace("\t", "").replace(u"\xa0", "")) - + # account coming mycomingval = cpt.xpath("./td[4]/text()")[0].replace("EUR", "").replace("\n", "").replace("\t", "") - + if mycomingval == '-': account.coming = float(0) else: @@ -87,15 +87,13 @@ class AccountsList(BasePage): # account._link_id url_to_parse = cpt.xpath('./td[1]/a/@href')[0] # link compte_id_re = re.compile(r'.*COMPTE_ACTIF=([^\&]+)\&.*') - account._link_id = '/fr/prive/mes-comptes/livret/consulter-situation/consulter-solde.jsp?COMPTE_ACTIF='+compte_id_re.search(str(url_to_parse)).groups()[0] - account._link_id = str(account._link_id) + account._link_id = '/fr/prive/mes-comptes/livret/consulter-situation/consulter-solde.jsp?COMPTE_ACTIF='+ \ + compte_id_re.search(url_to_parse).groups()[0] + account._link_id = account._link_id # account.label tpl = cpt.xpath("./td[2]/a/text()")[0].split(' ') - account.label = tpl[0] + u" " + tpl[1] - account.label = str(u""+account.label) - - account.raw = str(u""+account.label) + account.label = ' '.join(tpl[:2]) l.append(account) diff --git a/modules/fortuneo/pages/login.py b/modules/fortuneo/pages/login.py index 7e1fdac3..539c5e39 100644 --- a/modules/fortuneo/pages/login.py +++ b/modules/fortuneo/pages/login.py @@ -20,16 +20,25 @@ #from logging import error -from weboob.tools.browser import BasePage #, BrowserUnavailable +from weboob.tools.browser import BasePage, BrowserUnavailable __all__ = ['LoginPage'] class LoginPage(BasePage): - def login(self, login, passwd): + def login(self, login, passwd): + msgb = self.document.xpath(".//*[@id='message_client']/text()") + msga = ''.join(msgb) + msg = msga.strip("\n") + + if "maintenance" in msg: + print "Fortuneo: "+msg + raise BrowserUnavailable(msg) + self.browser.select_form(nr=3) self.browser['login'] = login self.browser['passwd'] = passwd self.browser.submit() + # vim:ts=4:sw=4 diff --git a/modules/fortuneo/test.py b/modules/fortuneo/test.py index 729018bd..d4d243c3 100644 --- a/modules/fortuneo/test.py +++ b/modules/fortuneo/test.py @@ -29,6 +29,3 @@ class FortuneoTest(BackendTest): a = l[0] list(self.backend.iter_coming(a)) list(self.backend.iter_history(a)) - -# vim:ts=4:sw=4 -