Support market accounts with browser2

This commit is contained in:
Florent 2014-03-28 13:23:53 +01:00
commit df85155463
3 changed files with 34 additions and 44 deletions

View file

@ -99,11 +99,9 @@ class INGBackend(BaseBackend, ICapBank, ICapBill):
return self.browser.transfer(account, recipient, amount, reason) return self.browser.transfer(account, recipient, amount, reason)
def iter_investment(self, account): def iter_investment(self, account):
with self.browser: if not isinstance(account, Account):
if not isinstance(account, Account): account = self.get_account(account)
account = self.get_account(account) return self.browser.get_investments(account)
for investment in self.browser.get_investments(account):
yield investment
def iter_subscription(self): def iter_subscription(self):
for subscription in self.browser.get_subscriptions(): for subscription in self.browser.get_subscriptions():

View file

@ -53,6 +53,7 @@ class IngBrowser(LoginBrowser):
starttitre = URL('/general\?command=goToAccount&zone=COMPTE', TitrePage) starttitre = URL('/general\?command=goToAccount&zone=COMPTE', TitrePage)
titrepage = URL('https://bourse.ingdirect.fr/priv/portefeuille-TR.php', TitrePage) titrepage = URL('https://bourse.ingdirect.fr/priv/portefeuille-TR.php', TitrePage)
titrehistory = URL('https://bourse.ingdirect.fr/priv/compte.php\?ong=3', TitreHistory) titrehistory = URL('https://bourse.ingdirect.fr/priv/compte.php\?ong=3', TitreHistory)
titrerealtime = URL('https://bourse.ingdirect.fr/streaming/compteTempsReelCK.php', TitrePage)
# CapBill # CapBill
@ -104,8 +105,8 @@ class IngBrowser(LoginBrowser):
if not isinstance(account, Account): if not isinstance(account, Account):
account = self.get_account(account) account = self.get_account(account)
if account.type == Account.TYPE_MARKET: if account.type == Account.TYPE_MARKET:
for tr in self.get_history_titre(account): for result in self.get_history_titre(account):
yield tr yield result
return return
elif account.type != Account.TYPE_CHECKING and\ elif account.type != Account.TYPE_CHECKING and\
account.type != Account.TYPE_SAVINGS: account.type != Account.TYPE_SAVINGS:
@ -190,7 +191,7 @@ class IngBrowser(LoginBrowser):
def go_investments(self, account): def go_investments(self, account):
if self.where != "start": if self.where != "start":
self.location(self.accountspage) self.accountspage.go()
data = {"AJAX:EVENTS_COUNT": 1, data = {"AJAX:EVENTS_COUNT": 1,
"AJAXREQUEST": "_viewRoot", "AJAXREQUEST": "_viewRoot",
"ajaxSingle": "index:setAccount", "ajaxSingle": "index:setAccount",
@ -200,23 +201,23 @@ class IngBrowser(LoginBrowser):
"javax.faces.ViewState": account._jid, "javax.faces.ViewState": account._jid,
"cptnbr": account._id "cptnbr": account._id
} }
self.location(self.accountspage, urllib.urlencode(data)) self.accountspage.go(data=data)
self.location('https://secure.ingdirect.fr/general?command=goToAccount&zone=COMPTE')
self.where = "titre"
self.location(self.titrepage) self.starttitre.go()
self.where = "titre"
self.titrepage.go()
def get_investments(self, account): def get_investments(self, account):
if account.type != Account.TYPE_MARKET: if account.type != Account.TYPE_MARKET:
raise NotImplementedError() raise NotImplementedError()
self.go_investments(account) self.go_investments(account)
self.location('https://bourse.ingdirect.fr/streaming/compteTempsReelCK.php') self.titrerealtime.go()
return self.page.iter_investments() return self.page.iter_investments()
def get_history_titre(self, account): def get_history_titre(self, account):
self.go_investments(account) self.go_investments(account)
self.location('https://bourse.ingdirect.fr/priv/compte.php?ong=3') self.titrehistory.go()
return self.page.iter_history() return self.page.iter_history()
def get_subscriptions(self): def get_subscriptions(self):

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2013 Florent Fourcot # Copyright(C) 2013-2014 Florent Fourcot
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -19,35 +19,34 @@
from decimal import Decimal from decimal import Decimal
from datetime import date
from weboob.capabilities.bank import Investment from weboob.capabilities.bank import Investment
from weboob.tools.browser import BasePage from weboob.tools.browser2.page import RawPage, HTMLPage, method, ListElement, ItemElement
from weboob.tools.browser2.filters import CleanDecimal, CleanText, Date
from weboob.tools.capabilities.bank.transactions import FrenchTransaction from weboob.tools.capabilities.bank.transactions import FrenchTransaction
__all__ = ['TitrePage'] __all__ = ['TitrePage']
class Transaction(FrenchTransaction): class Transaction(FrenchTransaction):
pass pass
class TitrePage(BasePage):
def on_loaded(self):
pass
class TitrePage(RawPage):
def iter_investments(self): def iter_investments(self):
# We did not get some html, but something like that (XX is a quantity, YY a price): # We did not get some html, but something like that (XX is a quantity, YY a price):
# message='[...] # message='[...]
#popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY €#YY,YY €#1 YYY,YY €#-YYY,YY €#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&pl=6&nc=1& #popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY €#YY,YY €#1 YYY,YY €#-YYY,YY €#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&pl=6&nc=1&
#popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY €#YY,YYY €#YYY,YY €#YY,YY €#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&pl=6&nc=1& #popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY €#YY,YYY €#YYY,YY €#YY,YY €#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&pl=6&nc=1&
# [...] # [...]
lines = self.document.split("popup=2") lines = self.doc.split("popup=2")
lines.pop(0) lines.pop(0)
for line in lines: for line in lines:
columns = line.split('#') columns = line.split('#')
code = columns[0].split('{')[2] code = columns[0].split('{')[2]
invest = Investment(code) invest = Investment(code)
invest.code = code invest.code = unicode(code)
invest.label = columns[0].split('{')[-1] invest.label = unicode(columns[0].split('{')[-1])
invest.quantity = int(columns[1]) invest.quantity = int(columns[1])
invest.unitprice = Decimal(FrenchTransaction.clean_amount(columns[2])) invest.unitprice = Decimal(FrenchTransaction.clean_amount(columns[2]))
invest.unitvalue = Decimal(FrenchTransaction.clean_amount(columns[3])) invest.unitvalue = Decimal(FrenchTransaction.clean_amount(columns[3]))
@ -56,26 +55,18 @@ class TitrePage(BasePage):
yield invest yield invest
class TitreHistory(BasePage):
def on_loaded(self):
pass
def iter_history(self): class TitreHistory(HTMLPage):
try: @method
table = self.document.xpath('//table[@class="datas retour"]')[0] class iter_history(ListElement):
except IndexError: item_xpath = '//table[@class="datas retour"]/tr'
return # noop
trs = table.xpath('tr') class item(ItemElement):
trs.pop(0) klass = Transaction
trs.pop(-1)
for tr in trs: def condition(self):
td = tr.xpath('td') return len(self.el.xpath('td[@class="impaire"]')) > 0
op = Transaction(1)
textraw = td[3].text_content() obj_raw = Transaction.Raw('td[4] | td[3]/a')
if len(td[2].xpath('a')) > 0: obj_date = Date(CleanText('td[2]'), dayfirst=True)
textraw += u" " + td[2].xpath('a')[0].text_content() obj_amount = CleanDecimal('td[7]')
amount = op.clean_amount(td[6].text_content())
op.parse(date(*reversed([int(x) for x in td[1].text_content().split('/')])), raw = textraw)
op.amount = Decimal(amount)
yield op