def get_investments(self): for line in self.document.xpath('//table[@id="t_intraday"]/tbody/tr'): if line.find_class('categorie') or line.find_class( 'detail') or line.find_class('detail02'): continue cols = line.findall('td') inv = Investment() inv.label = self.parser.tocleanstring(cols[self.COL_LABEL]) link = cols[self.COL_LABEL].xpath( './a[contains(@href, "cdReferentiel")]')[0] inv.id = unicode( re.search('cdReferentiel=(.*)', link.attrib['href']).group(1)) inv.code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1) inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY]) inv.unitprice = self.parse_decimal(cols[self.COL_UNITPRICE]) inv.unitvalue = self.parse_decimal(cols[self.COL_UNITVALUE]) inv.valuation = self.parse_decimal(cols[self.COL_VALUATION]) diff = cols[self.COL_PERF].text.strip() if diff == "-": inv.diff = NotAvailable else: inv.diff = Decimal(Transaction.clean_amount(diff)) 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.code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1) inv.label = CleanText(None).filter(cols[self.COL_LABEL]) inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY]) inv.unitprice = self.parse_decimal(cols[self.COL_UNITPRICE]) inv.unitvalue = self.parse_decimal(cols[self.COL_UNITVALUE]) 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]) inv.diff = self.parse_decimal(cols[self.COL_PERF]) diff_percent = self.parse_decimal(cols[self.COL_PERF_PERCENT]) inv.diff_percent = diff_percent / 100 if diff_percent else NotAvailable if is_isin_valid(inv.code): inv.code_type = Investment.CODE_TYPE_ISIN yield inv
def get_investments(self, account): if account is not None: # the balance is highly dynamic, fetch it along with the investments to grab a snapshot account.balance = CleanDecimal(None, replace_dots=True).filter(self.get_balance(account.type)) for line in self.doc.xpath('//table[@id="t_intraday"]/tbody/tr'): if line.find_class('categorie') or line.find_class('detail') or line.find_class('detail02'): continue cols = line.findall('td') inv = Investment() inv.label = CleanText(None).filter(cols[self.COL_LABEL]) link = cols[self.COL_LABEL].xpath('./a[contains(@href, "cdReferentiel")]')[0] inv.id = re.search('cdReferentiel=(.*)', link.attrib['href']).group(1) inv.code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1) 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], False) inv.valuation = self.parse_decimal(cols[self.COL_VALUATION], True) diff = cols[self.COL_PERF].text.strip() if diff == "-": inv.diff = NotAvailable else: inv.diff = CleanDecimal(None, replace_dots=True).filter(diff) if is_isin_valid(inv.code): inv.code_type = Investment.CODE_TYPE_ISIN yield inv if account.type != account.TYPE_MARKET: valuation = CleanDecimal(None, True).filter(self.doc.xpath('//*[@id="valorisation_compte"]/table/tr[3]/td[2]')) yield create_french_liquidity(valuation)
def get_investments(self): for line in self.document.xpath('//table[@id="tableau_support"]/tbody/tr'): cols = line.findall('td') inv = Investment() inv.id = unicode(re.search('cdReferentiel=(.*)', cols[self.COL_LABEL].find('a').attrib['href']).group(1)) inv.code = re.match('^[A-Z]+[0-9]+(.*)$', inv.id).group(1) inv.label = self.parser.tocleanstring(cols[self.COL_LABEL]) inv.quantity = self.parse_decimal(cols[self.COL_QUANTITY]) inv.unitprice = self.parse_decimal(cols[self.COL_UNITPRICE]) inv.unitvalue = self.parse_decimal(cols[self.COL_UNITVALUE]) inv.valuation = self.parse_decimal(cols[self.COL_VALUATION]) inv.diff = self.parse_decimal(cols[self.COL_PERF]) yield inv
def iter_investment(self): rows = self.document.xpath('//table[@id="mefav_repartition_supports_BPF"]//tr') or \ self.document.xpath('//tbody[@id="mefav_repartition_supports"]//tr') for tr in rows: cells = clean_cells(tr.findall('td')) cells[3:] = clean_amounts(cells[3:]) inv = Investment() inv.label, _, inv.code, inv.quantity, inv.unitvalue, inv.valuation, _ = cells if inv.code: inv.id = inv.code if not inv.unitvalue: # XXX Fonds eu Euros inv.code = u'XX' + re.sub(ur'[^A-Za-z0-9]', u'', inv.label).upper() inv.description = u'' yield inv