boursorama: support market investments

This commit is contained in:
Romain Bignon 2015-08-26 20:38:04 +02:00 committed by Romain Bignon
commit eab5e13189
4 changed files with 42 additions and 12 deletions

View file

@ -24,7 +24,7 @@ from .card_history import CardHistory
from .accounts_list import AccountsList
from .login import LoginPage, ProfilIncomplete, UpdateInfoPage
from .two_authentication import AuthenticationPage
from .investment import AccountInvestment, InvestmentDetail
from .investment import AccountMarket, AccountLifeInsurance, InvestmentDetail
class AccountPrelevement(AccountsList):
@ -37,6 +37,7 @@ __all__ = ['LoginPage',
'CardHistory',
'UpdateInfoPage',
'AuthenticationPage',
'AccountInvestment',
'AccountMarket',
'AccountLifeInsurance',
'InvestmentDetail',
]

View file

@ -28,17 +28,22 @@ from weboob.tools.capabilities.bank.transactions import FrenchTransaction
class AccountsList(Page):
def on_loaded(self):
pass
ACCOUNT_TYPES = {u'banque': Account.TYPE_CHECKING,
u'épargne': Account.TYPE_SAVINGS,
u'crédit': Account.TYPE_LOAN,
u'assurance vie': Account.TYPE_LIFE_INSURANCE,
u'bourse': Account.TYPE_MARKET,
}
def get_list(self):
blocks = self.document.xpath('//div[@id="synthese-list"]//div[@class="block"]')
for div in blocks:
block_title = ''.join(div.xpath('.//span[@class="title"]//text()')).lower()
block_title = ''.join(div.xpath('.//span[@class="title"]/a/text()')).lower().strip()
for tr in div.getiterator('tr'):
account = Account()
account.id = None
account._link_id = None
account.type = self.ACCOUNT_TYPES.get(block_title, Account.TYPE_UNKNOWN)
if 'assurance vie' in block_title:
# Life insurance accounts are investments
account.type = Account.TYPE_LIFE_INSURANCE

View file

@ -25,6 +25,30 @@ from weboob.deprecated.browser import Page
from weboob.capabilities.bank import Investment
from weboob.browser.filters.standard import CleanDecimal
Decimal = CleanDecimal(replace_dots=True).filter
class AccountMarket(Page):
def get_investment(self):
for tr in self.document.xpath('//table[@id="liste-positions-engagements"]/tbody/tr'):
cells = tr.xpath('./td')
if len(cells) < 6:
continue
inv = Investment()
inv.label = self.parser.tocleanstring(cells[0].xpath('.//a')[0])
isin_div = cells[0].xpath('.//div')
if len(isin_div) > 0:
inv.id = inv.code = self.parser.tocleanstring(isin_div[0])
inv.quantity = Decimal(cells[1])
inv.unitprice = Decimal(cells[2])
inv.unitvalue = Decimal(cells[3])
inv.valuation = Decimal(cells[4])
inv.diff = Decimal(cells[5])
inv._detail_url = None
yield inv
_el_to_string = XPath('string()')
@ -39,15 +63,13 @@ class IsinMixin(object):
return mobj.group(1)
class AccountInvestment(IsinMixin, Page):
class AccountLifeInsurance(IsinMixin, Page):
_re_isin = re.compile(r'isin=(\w+)')
_tr_list = XPath('//div[@id="content-gauche"]//table[@class="list"]/tbody/tr')
_td_list = XPath('./td')
_link = XPath('./td[1]/a/@href')
def get_investment(self):
Decimal = CleanDecimal(replace_dots=True).filter
for tr in self._tr_list(self.document):
cells = list(el_to_string(td) for td in self._td_list(tr))
link = unicode(self._link(tr)[0])