def iter_investment(self, account): for row, elem_repartition, elem_pocket, elem_diff in self.iter_invest_rows(account=account): inv = Investment() inv._account = account inv._el_pocket = elem_pocket inv.label = CleanText('.//td[1]')(row) inv.valuation = MyDecimal('.//td[2]')(row) # On all Cmes children the row shows percentages and the popup shows absolute values in currency. # On Cmes it is mirrored, the popup contains the percentage. is_mirrored = '%' in row.text_content() if not is_mirrored: inv.diff = MyDecimal('.//td[3]')(row) if elem_diff is not None: inv.diff_ratio = Eval(lambda x: x / 100, MyDecimal(Regexp(CleanText('.'), r'([+-]?[\d\s]+[\d,]+)\s*%')))(elem_diff) else: inv.diff = MyDecimal('.')(elem_diff) if elem_diff is not None: inv.diff_ratio = Eval(lambda x: x / 100, MyDecimal(Regexp(CleanText('.//td[3]'), r'([+-]?[\d\s]+[\d,]+)\s*%')))(row) if account.balance != 0: inv.portfolio_share = inv.valuation / account.balance yield inv
def iter_investments(self, account): for row, elem_repartition, elem_pocket, elem_diff in self.iter_invest_rows( account=account): inv = Investment() inv._account = account inv._el_pocket = elem_pocket inv.label = CleanText('.//td[1]')(row) _url = Link('.//td[1]/a', default=None)(row) if _url: inv._url = self.absurl(_url) else: # If _url is None, self.absurl returns the BASEURL, so we need to set the value manually. inv._url = None inv.valuation = MyDecimal('.//td[2]')(row) # On all Cmes children the row shows percentages and the popup shows absolute values in currency. # On Cmes it is mirrored, the popup contains the percentage. is_mirrored = '%' in row.text_content() if not is_mirrored: inv.diff = MyDecimal('.//td[3]')(row) if elem_diff is not None: inv.diff_ratio = Eval( lambda x: x / 100, MyDecimal( Regexp(CleanText('.'), r'([+-]?[\d\s]+[\d,]+)\s*%')))(elem_diff) else: inv.diff = MyDecimal('.')(elem_diff) if elem_diff is not None: inv.diff_ratio = Eval( lambda x: x / 100, MyDecimal( Regexp(CleanText('.//td[3]'), r'([+-]?[\d\s]+[\d,]+)\s*%')))(row) yield inv
def get_investments(self, account): for line in self.doc.xpath('//table[@id="tableau_support"]/tbody/tr'): cols = line.findall('td') inv = Investment() inv.id = re.search('cdReferentiel=(.*)', cols[self.COL_LABEL].find('a').attrib['href']).group(1) inv.label = CleanText(None).filter(cols[self.COL_LABEL]) inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY], True) inv.unitprice = self.parse_decimal(cols[self.COL_UNITPRICE], True) inv.unitvalue = self.parse_decimal(cols[self.COL_UNITVALUE], True) inv.vdate = Date(CleanText(cols[self.COL_DATE], default=NotAvailable), dayfirst=True, default=NotAvailable)(self.doc) inv.valuation = self.parse_decimal(cols[self.COL_VALUATION], True) inv.diff = self.parse_decimal(cols[self.COL_PERF], True) diff_percent = self.parse_decimal(cols[self.COL_PERF_PERCENT], True) inv.diff_ratio = diff_percent / 100 if diff_percent else NotAvailable code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1) if is_isin_valid(code): inv.code = CleanText().filter(code) inv.code_type = Investment.CODE_TYPE_ISIN else: inv.code = inv.code_type = NotAvailable yield inv