add investment to boursorama bank module

This commit is contained in:
smurail 2014-10-23 13:30:02 +02:00
commit 8672a6b443
5 changed files with 164 additions and 12 deletions

View file

@ -20,10 +20,14 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import re
from collections import defaultdict
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
from weboob.capabilities.bank import Account
from .pages import LoginPage, AccountsList, AccountHistory, CardHistory, UpdateInfoPage, AuthenticationPage
from .pages import (LoginPage, AccountsList, AccountHistory, CardHistory, UpdateInfoPage,
AuthenticationPage, AccountInvestment, InvestmentDetail)
__all__ = ['Boursorama']
@ -36,7 +40,8 @@ class BrowserIncorrectAuthenticationCode(BrowserIncorrectPassword):
class Boursorama(Browser):
DOMAIN = 'www.boursorama.com'
PROTOCOL = 'https'
CERTHASH = ['6bdf8b6dd177bd417ddcb1cfb818ede153288e44115eb269f2ddd458c8461039', 'b290ef629c88f0508e9cc6305421c173bd4291175e3ddedbee05ee666b34c20e']
CERTHASH = ['6bdf8b6dd177bd417ddcb1cfb818ede153288e44115eb269f2ddd458c8461039',
'b290ef629c88f0508e9cc6305421c173bd4291175e3ddedbee05ee666b34c20e']
ENCODING = None # refer to the HTML encoding
PAGES = {
'.*/connexion/securisation/index.phtml': AuthenticationPage,
@ -46,6 +51,8 @@ class Boursorama(Browser):
'.*/comptes/banque/cartes/mouvements.phtml.*': CardHistory,
'.*/comptes/epargne/mouvements.phtml.*': AccountHistory,
'.*/date_anniversaire.phtml.*': UpdateInfoPage,
'.*/detail.phtml.*': AccountInvestment,
'.*/opcvm.phtml.*': InvestmentDetail
}
def __init__(self, device="weboob", enable_twofactors=False,
@ -136,5 +143,29 @@ class Boursorama(Browser):
link = self.page.get_next_url()
def get_investment(self, account):
if account.type != Account.TYPE_MARKET or not account._detail_url:
raise NotImplementedError()
self.location(account._detail_url)
seen = defaultdict(int)
def slugify(label):
label = label.upper().replace('FONDS EN EUROS (', '')[:12]
slug = re.sub(r'[^A-Za-z0-9]', ' ', label).strip()
slug = re.sub(r'\s+', '-', slug)
if label in seen:
counter = str(seen[slug])
slug = slug[:-len(counter)] + counter
seen[label] += 1
return slug
for inv in self.page.get_investment():
if inv._detail_url:
self.location(inv._detail_url)
self.page.get_investment_detail(inv)
if not inv.id:
inv.id = inv.code = 'XX' + slugify(inv.label)
yield inv
def transfer(self, from_id, to_id, amount, reason=None):
raise NotImplementedError()