Newer
Older
# coding: utf-8
from __future__ import unicode_literals
import re
from decimal import Decimal
from weboob.capabilities import NotAvailable
from weboob.capabilities.bank import Investment, AccountNotFound
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
from weboob.browser.elements import TableElement, ItemElement, method
from weboob.browser.pages import HTMLPage, LoggedPage, FormNotFound
from weboob.browser.filters.standard import (
CleanText, CleanDecimal, Field, Regexp, Eval, Date
from weboob.browser.filters.html import Link, XPathNotFound, TableCell
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from weboob.browser.filters.javascript import JSVar
from .account_pages import Transaction
""" Life insurance subsite related pages """
class LITransaction(FrenchTransaction):
PATTERNS = [
(re.compile(u'^(?P<text>Arbitrage.*)'), FrenchTransaction.TYPE_ORDER),
(re.compile(u'^(?P<text>Versement.*)'), FrenchTransaction.TYPE_DEPOSIT),
(re.compile(r'^(?P<text>.*)'), FrenchTransaction.TYPE_BANK),
]
class LifeInsurancePortal(LoggedPage, HTMLPage):
def is_here(self):
try:
self.get_form(name='FORM_ERISA')
except FormNotFound:
return False
return True
def on_load(self):
self.logger.debug('automatically following form')
form = self.get_form(name='FORM_ERISA')
form['token'] = JSVar(CleanText('//script'), var='document.FORM_ERISA.token.value')(self.doc)
form.submit()
class LifeInsuranceMain(LoggedPage, HTMLPage):
def on_load(self):
self.logger.debug('automatically following form')
form = self.get_form(name='formAccueil')
form.url = 'https://assurances.hsbc.fr/navigation'
form.submit()
class LifeInsurancesPage(LoggedPage, HTMLPage):
@method
class iter_history(TableElement):
head_xpath = '(//table)[1]/thead/tr/th'
item_xpath = '(//table)[1]/tbody/tr'
col_label = "Actes"
col_date = "Date d'effet"
col_amount = "Montant net"
col_gross_amount = "Montant brut"
class item(ItemElement):
klass = LITransaction
obj_raw = LITransaction.Raw(CleanText(TableCell('label')))
obj_date = Date(CleanText(TableCell('date')))
obj_amount = Transaction.Amount(TableCell('amount'), TableCell('gross_amount'), replace_dots=False)
@method
class iter_investments(TableElement):
head_xpath = '//div[contains(., "Détail de vos supports")]/following-sibling::div/table/thead/tr/th'
item_xpath = '//div[contains(., "Détail de vos supports")]/following-sibling::div/table/tbody/tr'
col_label = "Support"
col_vdate = "Date de valorisation *"
col_quantity = "Nombre d'unités de compte"
col_portfolio_share = "Répartition"
col_unitvalue = "Valeur liquidative"
col_support_value = "Valeur support"
class item(ItemElement):
klass = Investment
obj_label = CleanText(TableCell('label'))
obj_vdate = Date(CleanText(TableCell('vdate')), dayfirst=True)
obj_portfolio_share = Eval(lambda x: x / 100, CleanDecimal(TableCell('portfolio_share')))
obj_unitvalue = CleanDecimal(TableCell('unitvalue'), default=Decimal('1'))
obj_valuation = CleanDecimal(TableCell('support_value'))
def obj_code(self):
if "Fonds en euros" in Field('label')(self):
return NotAvailable
return Regexp(Link('.//a'), r'javascript:openSupportPerformanceWindow\(\'(.*?)\', \'(.*?)\'\)', '\\2')(self)
def obj_quantity(self):
# default for euro funds
return CleanDecimal(TableCell('quantity'), default=CleanDecimal(TableCell('support_value'))(self))(self)
def condition(self):
return len(self.el.xpath('.//td')) > 1
def get_lf_attributes(self, lfid):
attributes = {}
# values can be in JS var format but it's not mandatory param so we don't go to get the real value
try:
values = Regexp(Link('//a[contains(., "%s")]' % lfid[:-3].lstrip('0')), r'\((.*?)\)')(self.doc).replace(' ', '').replace('\'', '').split(',')
except XPathNotFound:
raise AccountNotFound('cannot find account id %s on life insurance site' % lfid)
keys = Regexp(CleanText('//script'), r'consultationContrat\((.*?)\)')(self.doc).replace(' ', '').split(',')
attributes = dict(zip(keys, values))
return attributes
def disconnect(self):
self.get_form(name='formDeconnexion').submit()
class LifeInsuranceUseless(LoggedPage, HTMLPage):
is_here = '//h1[text()="Assurance Vie"]'
##