Commit 7bcb4bcf authored by Edouard Lambert's avatar Edouard Lambert Committed by Romain Bignon

adding investments to apivie

parent d00bc07c
......@@ -20,7 +20,7 @@
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
from .pages import LoginPage, AccountsPage, OperationsPage
from .pages import LoginPage, AccountsPage, InvestmentsPage, OperationsPage
__all__ = ['ApivieBrowser']
......@@ -28,19 +28,23 @@ __all__ = ['ApivieBrowser']
class ApivieBrowser(Browser):
PROTOCOL = 'https'
DOMAIN = 'www.apivie.fr'
ENCODING = None
PAGES = {
'https?://www.apivie.fr/': LoginPage,
'https?://www.apivie.fr/accueil': LoginPage,
'https?://www.apivie.fr/perte.*': LoginPage,
'https?://www.apivie.fr/accueil-connect': AccountsPage,
'https?://www.apivie.fr/historique-contrat.*': OperationsPage,
'https?://[^/]+/': LoginPage,
'https?://[^/]+/accueil': LoginPage,
'https?://[^/]+/perte.*': LoginPage,
'https?://[^/]+/accueil-connect': AccountsPage,
'https?://[^/]+/synthese-contrat.*': InvestmentsPage,
'https?://[^/]+/historique-contrat.*': OperationsPage,
}
def __init__(self, website, *args, **kwargs):
self.DOMAIN = website
Browser.__init__(self, *args, **kwargs)
def home(self):
self.location('https://www.apivie.fr/accueil-connect')
self.location('https://%s/accueil-connect' % self.DOMAIN)
def login(self):
assert isinstance(self.username, basestring)
......@@ -67,6 +71,12 @@ class ApivieBrowser(Browser):
except StopIteration:
return None
def iter_investment(self, account):
self.location(self.buildurl('/synthese-contrat', contratId=account.id))
assert self.is_on_page(InvestmentsPage)
return self.page.iter_investment()
def iter_history(self, account):
self.location(self.buildurl('/historique-contrat', contratId=account.id))
......
......@@ -40,7 +40,8 @@ class ApivieModule(Module, CapBankWealth):
ValueBackendPassword('password', label='Mot de passe'))
def create_default_browser(self):
return self.create_browser(self.config['login'].get(),
return self.create_browser('www.apivie.fr',
self.config['login'].get(),
self.config['password'].get())
def iter_accounts(self):
......@@ -51,6 +52,10 @@ class ApivieModule(Module, CapBankWealth):
with self.browser:
return self.browser.get_account(_id)
def iter_investment(self, account):
with self.browser:
return self.browser.iter_investment(account)
def iter_history(self, account):
with self.browser:
return self.browser.iter_history(account)
......@@ -20,9 +20,10 @@
from decimal import Decimal
from weboob.capabilities.bank import Account
from weboob.capabilities.bank import Account, Investment
from weboob.deprecated.browser import Page
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
from weboob.browser.filters.standard import Date, CleanText
class LoginPage(Page):
......@@ -55,6 +56,27 @@ class AccountsPage(Page):
return account
class InvestmentsPage(Page):
COL_LABEL = 0
COL_CODE = 1
COL_VALUATION = 2
COL_PORTFOLIO_SHARE = 3
def iter_investment(self):
for line in self.document.xpath('//div[@class="supportTable"]//table/tbody/tr'):
tds = line.findall('td')
inv = Investment()
inv.vdate = Date(dayfirst=True).filter(CleanText().filter(self.document.xpath( \
'//div[@id="table-evolution-contrat"]//table/tbody/tr[1]/td[1]')))
inv.label = self.parser.tocleanstring(tds[self.COL_LABEL])
inv.code = self.parser.tocleanstring(tds[self.COL_CODE])
inv.valuation = Decimal(FrenchTransaction.clean_amount( \
self.parser.tocleanstring(tds[self.COL_VALUATION])))
inv.portfolio_share = Decimal(FrenchTransaction.clean_amount( \
self.parser.tocleanstring(tds[self.COL_PORTFOLIO_SHARE])))
yield inv
class Transaction(FrenchTransaction):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment