Exemple #1
0
    def iter_investment(self):
        for line in self.document.xpath('//table[contains(@class, "ca-data-table")]/descendant::tr[count(td)>=7]'):
            for sub in line.xpath('./td[@class="info-produit"]'):
                sub.drop_tree()
            cells = line.findall('td')

            if cells[self.COL_ID].find('div/a') is None:
                continue
            inv = Investment()
            inv.label = unicode(cells[self.COL_ID].find('div/a').text.strip())
            inv.code = cells[self.COL_ID].find('div/br').tail.strip().split(u'\xa0')[0]
            inv.quantity = self.parse_decimal(cells[self.COL_QUANTITY].find('span').text)
            inv.valuation = self.parse_decimal(cells[self.COL_VALUATION].text)
            inv.diff = self.parse_decimal(cells[self.COL_DIFF].text_content())
            if "%" in cells[self.COL_UNITPRICE].text and "%" in cells[self.COL_UNITVALUE].text:
                inv.unitvalue = inv.valuation / inv.quantity
                inv.unitprice = (inv.valuation - inv.diff) / inv.quantity
            else:
                inv.unitprice = self.parse_decimal(cells[self.COL_UNITPRICE].text)
                inv.unitvalue = self.parse_decimal(cells[self.COL_UNITVALUE].text)
            date = cells[self.COL_UNITVALUE].find('span').text
            if ':' in date:
                inv.vdate = ddate.today()
            else:
                day, month = map(int, date.split('/', 1))
                date_guesser = LinearDateGuesser()
                inv.vdate = date_guesser.guess_date(day, month)

            yield inv
Exemple #2
0
    def iter_investment(self):
        not_rounded_valuations = self.get_not_rounded_valuations()

        doc = self.browser.open('/brs/fisc/fisca10a.html').page.doc
        num_page = None

        try:
            num_page = int(CleanText('.')(doc.xpath(u'.//tr[contains(td[1], "Relevé des plus ou moins values latentes")]/td[2]')[0]).split('/')[1])
        except IndexError:
            pass

        docs = [doc]

        if num_page:
            for n in range(2, num_page + 1):
                docs.append(self.browser.open('%s%s' % ('/brs/fisc/fisca10a.html?action=12&numPage=', str(n))).page.doc)

        for doc in docs:
            # There are two different tables possible depending on the market account type.
            is_detailed = bool(doc.xpath(u'//span[contains(text(), "Années d\'acquisition")]'))
            tr_xpath = '//tr[@height and td[@colspan="6"]]' if is_detailed else '//tr[count(td)>5]'
            for tr in doc.xpath(tr_xpath):
                cells = tr.findall('td')

                inv = Investment()

                title_split = cells[self.COL_LABEL].xpath('.//span')[0].attrib['title'].split(' - ')
                inv.label = unicode(title_split[0])

                for code in title_split[1:]:
                    if is_isin_valid(code):
                        inv.code = unicode(code)
                        inv.code_type = Investment.CODE_TYPE_ISIN
                        break
                    else:
                        inv.code = NotAvailable
                        inv.code_type = NotAvailable

                if is_detailed:
                    inv.quantity = MyDecimal('.')(tr.xpath('./following-sibling::tr/td[2]')[0])
                    inv.unitprice = MyDecimal('.', replace_dots=True)(tr.xpath('./following-sibling::tr/td[3]')[1])
                    inv.unitvalue = MyDecimal('.', replace_dots=True)(tr.xpath('./following-sibling::tr/td[3]')[0])

                    try: # try to get not rounded value
                        inv.valuation = not_rounded_valuations[inv.label]
                    except KeyError: # ok.. take it from the page
                        inv.valuation = MyDecimal('.')(tr.xpath('./following-sibling::tr/td[4]')[0])

                    inv.diff = MyDecimal('.')(tr.xpath('./following-sibling::tr/td[5]')[0]) or \
                               MyDecimal('.')(tr.xpath('./following-sibling::tr/td[6]')[0])
                else:
                    inv.quantity = MyDecimal('.')(cells[self.COL_QUANTITY])
                    inv.diff = MyDecimal('.')(cells[self.COL_DIFF])
                    inv.unitprice = MyDecimal('.')(cells[self.COL_UNITPRICE].xpath('.//tr[1]/td[2]')[0])
                    inv.unitvalue = MyDecimal('.')(cells[self.COL_VALUATION].xpath('.//tr[1]/td[2]')[0])
                    inv.valuation = MyDecimal('.')(cells[self.COL_VALUATION].xpath('.//tr[2]/td[2]')[0])

                yield inv
Exemple #3
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        # popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY €#YY,YY €#1 YYY,YY €#-YYY,YY €#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&pl=6&nc=1&
        # popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY €#YY,YYY €#YYY,YY €#YY,YY €#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&pl=6&nc=1&
        # [...]
        lines = self.doc.split("popup=2")
        lines.pop(0)
        for line in lines:
            columns = line.split('#')
            _pl = columns[0].split('{')[1]
            _id = columns[0].split('{')[2]
            invest = Investment(_id)
            invest.label = unicode(columns[0].split('{')[-1])
            invest.code = unicode(_id)
            if ':' in invest.code:
                invest.code = self.browser.titrevalue.open(val=invest.code,pl=_pl).get_isin()
            # The code we got is not a real ISIN code.
            if not re.match('^[A-Z]{2}[\d]{10}$|^[A-Z]{2}[\d]{5}[A-Z]{1}[\d]{4}$', invest.code):
                m = re.search('\{([A-Z]{2}[\d]{10})\{|\{([A-Z]{2}[\d]{5}[A-Z]{1}[\d]{4})\{', line)
                if m:
                    invest.code = unicode(m.group(1) or m.group(2))
            quantity = FrenchTransaction.clean_amount(columns[1])
            if quantity != '':
                invest.quantity = Decimal(quantity)
            else:
                invest.quantity = NotAvailable
            unitprice = FrenchTransaction.clean_amount(columns[2])
            if unitprice != '':
                invest.unitprice = Decimal(unitprice)
            else:
                invest.unitprice = NotAvailable
            unitvalue = FrenchTransaction.clean_amount(columns[3])
            if unitvalue != '':
                invest.unitvalue = Decimal(unitvalue)
            else:
                invest.unitvalue = NotAvailable
            valuation = FrenchTransaction.clean_amount(columns[4])
            if valuation != '':
                invest.valuation = Decimal(valuation)
            else:
                # valuation is not nullable.
                invest.valuation = Decimal('0')
            diff = FrenchTransaction.clean_amount(columns[5])
            if diff != '':
                invest.diff = Decimal(diff)
            else:
                invest.diff = NotAvailable

            yield invest
Exemple #4
0
    def iter_investment(self):

        for line in self.document.xpath('//table[@summary and count(descendant::td) > 1]/tbody/tr'):
            cells = line.findall('td')
            if len(cells) < 5:
                continue

            inv = Investment()
            inv.label = unicode(cells[self.COL_ID].text_content().strip())
            a = cells[self.COL_ID].find('a')
            if a is not None:
                try:
                    inv.code = a.attrib['id']
                except KeyError:
                    #For "Mandat d'arbitrage" which is a recapitulatif of more investement
                    continue
            else:
                inv.code = NotAvailable
            inv.quantity = self.parse_decimal(cells[self.COL_QUANTITY].text_content())
            inv.unitvalue = self.parse_decimal(cells[self.COL_UNITVALUE].text_content())
            inv.valuation = self.parse_decimal(cells[self.COL_VALUATION].text_content())
            inv.unitprice = NotAvailable
            inv.diff = NotAvailable

            yield inv
Exemple #5
0
    def iter_investment(self):
        doc = self.browser.get_document(self.browser.openurl('/brs/fisc/fisca10a.html'), encoding='utf-8')
        num_page = None
        try:
            num_page = int(self.parser.tocleanstring(doc.xpath(u'.//tr[contains(td[1], "Relevé des plus ou moins values latentes")]/td[2]')[0]).split('/')[1])
        except IndexError:
            pass
        docs = [doc]
        if num_page:
            for n in range(2, num_page + 1):
                docs.append(self.browser.get_document(self.browser.openurl('%s%s' % ('/brs/fisc/fisca10a.html?action=12&numPage=', str(n))), encoding='utf-8'))

        for doc in docs:
            for tr in doc.xpath('//tr[count(td)=6 and td[1]/strong]'):
                cells = tr.findall('td')

                inv = Investment()
                inv.label = unicode(cells[self.COL_LABEL].xpath('.//span')[0].attrib['title'].split(' - ')[0])
                inv.code = unicode(cells[self.COL_LABEL].xpath('.//span')[0].attrib['title'].split(' - ')[1])
                inv.quantity = self.parse_decimal(cells[self.COL_QUANTITY])
                inv.unitprice = self.parse_decimal(tr.xpath('./following-sibling::tr/td[3]')[0])
                inv.unitvalue = self.parse_decimal(cells[self.COL_UNITVALUE])
                inv.valuation = self.parse_decimal(cells[self.COL_VALUATION])
                inv.diff = self.parse_decimal(cells[self.COL_DIFF])

                yield inv
Exemple #6
0
    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)
Exemple #7
0
    def iter_investment(self):
        doc = self.browser.get_document(self.browser.openurl('/brs/fisc/fisca10a.html'), encoding='utf-8')
        num_page = None
        try:
            num_page = int(self.parser.tocleanstring(doc.xpath(u'.//tr[contains(td[1], "Relevé des plus ou moins values latentes")]/td[2]')[0]).split('/')[1])
        except IndexError:
            pass
        docs = [doc]
        if num_page:
            for n in range(2, num_page + 1):
                docs.append(self.browser.get_document(self.browser.openurl('%s%s' % ('/brs/fisc/fisca10a.html?action=12&numPage=', str(n))), encoding='utf-8'))

        for doc in docs:
            for tr in doc.xpath('//tr[count(td)=6 and td[1]/strong]'):
                cells = tr.findall('td')

                inv = Investment()
                inv.label = unicode(cells[self.COL_LABEL].xpath('.//span')[0].attrib['title'].split(' - ')[0])
                inv.code = unicode(cells[self.COL_LABEL].xpath('.//span')[0].attrib['title'].split(' - ')[1])
                inv.quantity = self.parse_decimal(cells[self.COL_QUANTITY])
                inv.unitprice = self.parse_decimal(tr.xpath('./following-sibling::tr/td[3]')[0])
                inv.unitvalue = self.parse_decimal(cells[self.COL_UNITVALUE])
                inv.valuation = self.parse_decimal(cells[self.COL_VALUATION])
                inv.diff = self.parse_decimal(cells[self.COL_DIFF])

                yield inv
Exemple #8
0
    def get_market_investment(self):
        COL_LABEL = 0
        COL_QUANTITY = 1
        COL_UNITPRICE = 2
        COL_UNITVALUE = 3
        COL_VALUATION = 4
        COL_PERF = 5
        for table in self.document.xpath('//table[@class="datas-large"]'):
            for tr in table.xpath('.//tr[not(@class="entete")]'):
                cols = tr.findall('td')
                if len(cols) < 7:
                    continue
                delta = 0
                if len(cols) == 9:
                    delta = 1

                inv = Investment()
                inv.code = self.parser.tocleanstring(
                    cols[COL_LABEL + delta].xpath('.//span')[1])
                inv.label = self.parser.tocleanstring(
                    cols[COL_LABEL + delta].xpath('.//span')[0])
                inv.quantity = self.parse_decimal(cols[COL_QUANTITY + delta])
                inv.unitprice = self.parse_decimal(cols[COL_UNITPRICE + delta])
                inv.unitvalue = self.parse_decimal(cols[COL_UNITVALUE + delta])
                inv.valuation = self.parse_decimal(cols[COL_VALUATION + delta])
                inv.diff = self.parse_decimal(cols[COL_PERF + delta])

                yield inv
Exemple #9
0
    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
Exemple #10
0
    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
Exemple #11
0
    def get_market_investment(self):
        COL_LABEL = 0
        COL_QUANTITY = 1
        COL_UNITPRICE = 2
        COL_UNITVALUE = 3
        COL_VALUATION = 4
        COL_PERF = 5
        for table in self.document.xpath('//table[@class="datas-large"]'):
            for tr in table.xpath('.//tr[not(@class="entete")]'):
                cols = tr.findall('td')
                if len(cols) < 7:
                    continue
                delta = 0
                if len(cols) == 9:
                    delta = 1

                inv = Investment()
                inv.code = self.parser.tocleanstring(cols[COL_LABEL + delta].xpath('.//span')[1])
                inv.label = self.parser.tocleanstring(cols[COL_LABEL + delta].xpath('.//span')[0])
                inv.quantity = self.parse_decimal(cols[COL_QUANTITY + delta])
                inv.unitprice = self.parse_decimal(cols[COL_UNITPRICE + delta])
                inv.unitvalue = self.parse_decimal(cols[COL_UNITVALUE + delta])
                inv.valuation = self.parse_decimal(cols[COL_VALUATION + delta])
                inv.diff = self.parse_decimal(cols[COL_PERF + delta])

                yield inv
Exemple #12
0
    def iter_investment(self):

        for line in self.document.xpath(
                '//table[@summary and count(descendant::td) > 1]/tbody/tr'):
            cells = line.findall('td')
            if len(cells) < 5:
                continue

            inv = Investment()
            inv.label = unicode(cells[self.COL_ID].text_content().strip())
            a = cells[self.COL_ID].find('a')
            if a is not None:
                try:
                    inv.code = a.attrib['id']
                except KeyError:
                    #For "Mandat d'arbitrage" which is a recapitulatif of more investement
                    continue
            else:
                inv.code = NotAvailable
            inv.quantity = self.parse_decimal(
                cells[self.COL_QUANTITY].text_content())
            inv.unitvalue = self.parse_decimal(
                cells[self.COL_UNITVALUE].text_content())
            inv.valuation = self.parse_decimal(
                cells[self.COL_VALUATION].text_content())
            inv.unitprice = NotAvailable
            inv.diff = NotAvailable

            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)
Exemple #14
0
    def get_market_investment(self):
        if CleanText('//div[contains(text(), "restreint aux fonctions de bourse")]')(self.doc):
            return

        COL_LABEL = 0
        COL_QUANTITY = 1
        COL_UNITPRICE = 2
        COL_UNITVALUE = 3
        COL_VALUATION = 4
        COL_PERF = 5


        for table in self.doc.xpath('//table[@class="datas-large"]'):
            for tr in table.xpath('.//tr[not(@class="entete")]'):
                cols = tr.findall('td')
                if len(cols) < 7:
                    continue
                delta = 0
                if len(cols) == 9:
                    delta = 1

                inv = Investment()
                inv.code = CleanText('.')(cols[COL_LABEL + delta].xpath('.//span')[1]).split(' ')[0].split(u'\xa0')[0]
                inv.label = CleanText('.')(cols[COL_LABEL + delta].xpath('.//span')[0])
                inv.quantity = MyDecimal('.')(cols[COL_QUANTITY + delta])
                inv.unitprice = MyDecimal('.')(cols[COL_UNITPRICE + delta])
                inv.unitvalue = MyDecimal('.')(cols[COL_UNITVALUE + delta])
                inv.valuation = MyDecimal('.')(cols[COL_VALUATION + delta])
                inv.diff = MyDecimal('.')(cols[COL_PERF + delta])

                yield inv
Exemple #15
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        # popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY &euro;#YY,YY &euro;#1 YYY,YY &euro;#-YYY,YY &euro;#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&amp;pl=6&amp;nc=1&amp;
        # popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY &euro;#YY,YYY &euro;#YYY,YY &euro;#YY,YY &euro;#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&amp;pl=6&amp;nc=1&amp;
        # [...]
        lines = self.doc.split("popup=2")
        lines.pop(0)
        for line in lines:
            columns = line.split('#')
            _id = columns[0].split('{')[2]
            invest = Investment(_id)
            invest.label = unicode(columns[0].split('{')[-1])
            invest.code = NotAvailable
            if ':' in _id:
                invest.description = unicode(_id.split(':')[1])
            invest.quantity = Decimal(
                FrenchTransaction.clean_amount(columns[1]))
            invest.unitprice = Decimal(
                FrenchTransaction.clean_amount(columns[2]))
            invest.unitvalue = Decimal(
                FrenchTransaction.clean_amount(columns[3]))
            invest.valuation = Decimal(
                FrenchTransaction.clean_amount(columns[4]))
            invest.diff = Decimal(FrenchTransaction.clean_amount(columns[5]))

            yield invest
Exemple #16
0
    def iter_investment(self):
        for line in self.document.xpath('//table[contains(@class, "ca-data-table")]/descendant::tr[count(td)=8]'):
            cells = line.findall('td')

            inv = Investment()
            inv.label = unicode(cells[self.COL_ID].find('div/a').text.strip())
            inv.code = cells[self.COL_ID].find('div/br').tail.strip()
            inv.quantity = self.parse_decimal(cells[self.COL_QUANTITY].find('span').text)
            inv.valuation = self.parse_decimal(cells[self.COL_VALUATION].text)
            inv.diff = self.parse_decimal(cells[self.COL_DIFF].text_content())
            if "%" in cells[self.COL_UNITPRICE].text and "%" in cells[self.COL_UNITVALUE].text:
                inv.unitvalue = inv.valuation / inv.quantity
                inv.unitprice = (inv.valuation - inv.diff) / inv.quantity
            else:
                inv.unitprice = self.parse_decimal(cells[self.COL_UNITPRICE].text)
                inv.unitvalue = self.parse_decimal(cells[self.COL_UNITVALUE].text)

            yield inv
Exemple #17
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        # popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY &euro;#YY,YY &euro;#1 YYY,YY &euro;#-YYY,YY &euro;#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&amp;pl=6&amp;nc=1&amp;
        # popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY &euro;#YY,YYY &euro;#YYY,YY &euro;#YY,YY &euro;#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&amp;pl=6&amp;nc=1&amp;
        # [...]
        lines = self.doc.split("popup=2")
        lines.pop(0)
        for line in lines:
            columns = line.split('#')
            _id = columns[0].split('{')[2]
            invest = Investment(_id)
            invest.label = unicode(columns[0].split('{')[-1])
            invest.code = unicode(_id)
            if ':' in invest.code:
                invest.code = self.browser.titrevalue.open(
                    val=invest.code).get_isin()
            quantity = FrenchTransaction.clean_amount(columns[1])
            if quantity != '':
                invest.quantity = Decimal(quantity)
            else:
                invest.quantity = NotAvailable
            unitprice = FrenchTransaction.clean_amount(columns[2])
            if unitprice != '':
                invest.unitprice = Decimal(unitprice)
            else:
                invest.unitprice = NotAvailable
            unitvalue = FrenchTransaction.clean_amount(columns[3])
            if unitvalue != '':
                invest.unitvalue = Decimal(unitvalue)
            else:
                invest.unitvalue = NotAvailable
            valuation = FrenchTransaction.clean_amount(columns[4])
            if valuation != '':
                invest.valuation = Decimal(valuation)
            else:
                invest.valuation = NotAvailable
            diff = FrenchTransaction.clean_amount(columns[5])
            if diff != '':
                invest.diff = Decimal(diff)
            else:
                invest.diff = NotAvailable

            yield invest
Exemple #18
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        # popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY &euro;#YY,YY &euro;#1 YYY,YY &euro;#-YYY,YY &euro;#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&amp;pl=6&amp;nc=1&amp;
        # popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY &euro;#YY,YYY &euro;#YYY,YY &euro;#YY,YY &euro;#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&amp;pl=6&amp;nc=1&amp;
        # [...]
        lines = self.doc.split("popup=2")
        lines.pop(0)
        invests = []
        for line in lines:
            columns = line.split('#')
            _pl = columns[0].split('{')[1]
            _id = columns[0].split('{')[2]
            invest = Investment(_id)
            invest.label = unicode(columns[0].split('{')[-1])
            invest.code = unicode(_id)
            if ':' in invest.code:
                invest.code = self.browser.titrevalue.open(val=invest.code,pl=_pl).get_isin()
            # The code we got is not a real ISIN code.
            if not re.match('^[A-Z]{2}[\d]{10}$|^[A-Z]{2}[\d]{5}[A-Z]{1}[\d]{4}$', invest.code):
                m = re.search('\{([A-Z]{2}[\d]{10})\{|\{([A-Z]{2}[\d]{5}[A-Z]{1}[\d]{4})\{', line)
                if m:
                    invest.code = unicode(m.group(1) or m.group(2))

            quantity = FrenchTransaction.clean_amount(columns[1])
            invest.quantity = CleanDecimal(default=NotAvailable).filter(quantity)

            unitprice = FrenchTransaction.clean_amount(columns[2])
            invest.unitprice = CleanDecimal(default=NotAvailable).filter(unitprice)

            unitvalue = FrenchTransaction.clean_amount(columns[3])
            invest.unitvalue = CleanDecimal(default=NotAvailable).filter(unitvalue)

            valuation = FrenchTransaction.clean_amount(columns[4])
            # valuation is not nullable, use 0 as default value
            invest.valuation = CleanDecimal(default=Decimal('0')).filter(valuation)

            diff = FrenchTransaction.clean_amount(columns[5])
            invest.diff = CleanDecimal(default=NotAvailable).filter(diff)

            # On some case we have a multine investment with a total column
            # for now we have only see this on 2 lines, we will need to adapt it when o
            if columns[9] == u'|Total' and _id == 'fichevaleur':
                prev_inv = invest
                invest = invests.pop(-1)
                if prev_inv.quantity:
                    invest.quantity = invest.quantity + prev_inv.quantity
                if prev_inv.valuation:
                    invest.valuation = invest.valuation + prev_inv.valuation
                if prev_inv.diff:
                    invest.diff = invest.diff + prev_inv.diff

            invests.append(invest)

        for invest in invests:
            yield invest
Exemple #19
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        # popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY &euro;#YY,YY &euro;#1 YYY,YY &euro;#-YYY,YY &euro;#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&amp;pl=6&amp;nc=1&amp;
        # popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY &euro;#YY,YYY &euro;#YYY,YY &euro;#YY,YY &euro;#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&amp;pl=6&amp;nc=1&amp;
        # [...]
        lines = self.doc.split("popup=2")
        lines.pop(0)
        for line in lines:
            columns = line.split('#')
            _id = columns[0].split('{')[2]
            invest = Investment(_id)
            invest.label = unicode(columns[0].split('{')[-1])
            invest.code = _id.split(':')[0]
            if ':' in _id:
                invest.description = unicode(_id.split(':')[1])
            quantity = FrenchTransaction.clean_amount(columns[1])
            if quantity != '':
                invest.quantity = Decimal(quantity)
            else:
                invest.quantity = NotAvailable
            unitprice = FrenchTransaction.clean_amount(columns[2])
            if unitprice != '':
                invest.unitprice = Decimal(unitprice)
            else:
                invest.unitprice = NotAvailable
            unitvalue = FrenchTransaction.clean_amount(columns[3])
            if unitvalue != '':
                invest.unitvalue = Decimal(unitvalue)
            else:
                invest.unitvalue = NotAvailable
            valuation = FrenchTransaction.clean_amount(columns[4])
            if valuation != '':
                invest.valuation = Decimal(valuation)
            else:
                invest.valuation = NotAvailable
            diff = FrenchTransaction.clean_amount(columns[5])
            if diff != '':
                invest.diff = Decimal(diff)
            else:
                invest.diff = NotAvailable

            yield invest
Exemple #20
0
 def iter_investments(self):
     for support in self.path(self.investments_path):
         inv = Investment()
         inv.code = inv.id = support['securityCode']
         inv.quantity = support['quantityOwned']
         inv.unitvalue = support['currentQuote']
         inv.unitprice = support['averagePrice']
         inv.label = support['securityName']
         inv.valuation = support['valorizationValuation']
         inv.diff = support['profitLossValorisation']
         inv.set_empty_fields(NotAvailable)
         yield inv
Exemple #21
0
    def iter_investment(self):
        for tbody in self.doc.xpath(u'//table[@summary="Contenu du portefeuille valorisé"]/tbody'):
            inv = Investment()
            inv.label = CleanText('.')(tbody.xpath('./tr[1]/td[1]/a/span')[0])
            inv.code = CleanText('.')(tbody.xpath('./tr[1]/td[1]/a')[0]).split(' - ')[1]
            inv.quantity = self.parse_decimal(tbody.xpath('./tr[2]/td[2]')[0])
            inv.unitvalue = self.parse_decimal(tbody.xpath('./tr[2]/td[3]')[0])
            inv.unitprice = self.parse_decimal(tbody.xpath('./tr[2]/td[5]')[0])
            inv.valuation = self.parse_decimal(tbody.xpath('./tr[2]/td[4]')[0])
            inv.diff = self.parse_decimal(tbody.xpath('./tr[2]/td[7]')[0])

            yield inv
Exemple #22
0
 def iter_investments(self):
     for support in self.path(self.investments_path):
         inv = Investment()
         inv.code = inv.id = support['securityCode']
         inv.quantity = support['quantityOwned']
         inv.unitvalue = support['currentQuote']
         inv.unitprice = support['averagePrice']
         inv.label = support['securityName']
         inv.valuation = support['valorizationValuation']
         inv.diff = support['profitLossValorisation']
         inv.set_empty_fields(NotAvailable)
         yield inv
Exemple #23
0
    def iter_investment(self):
        for tbody in self.document.xpath(u'//table[@summary="Contenu du portefeuille valorisé"]/tbody'):

            inv = Investment()
            inv.label = self.parser.tocleanstring(tbody.xpath('./tr[1]/td[1]/a/span')[0])
            inv.code = self.parser.tocleanstring(tbody.xpath('./tr[1]/td[1]/a')[0]).split(' - ')[1]
            inv.quantity = self.parse_decimal(tbody.xpath('./tr[2]/td[2]')[0])
            inv.unitvalue = self.parse_decimal(tbody.xpath('./tr[2]/td[3]')[0])
            inv.unitprice = self.parse_decimal(tbody.xpath('./tr[2]/td[5]')[0])
            inv.valuation = self.parse_decimal(tbody.xpath('./tr[2]/td[4]')[0])
            inv.diff = self.parse_decimal(tbody.xpath('./tr[2]/td[7]')[0])

            yield inv
Exemple #24
0
    def get_investment(self):
        Decimal = CleanDecimal(replace_dots=True).filter

        for tr in self._tr_list(self.document):
            cells = list(el_to_string(td) for td in self._td_list(tr))
            link = unicode(self._link(tr)[0])

            '''

            Boursorama table cells
            ----------------------

            0. Fonds
            1. Date de valeur
            2. Valeur de part
            3. Nombre de parts
            4. Contre valeur
            5. Prix revient
            6. +/- value en €*
            7. +/- value en %*

            Investment model
            ----------------

            label =       StringField('Label of stocks')
            code =        StringField('Identifier of the stock (ISIN code)')
            description = StringField('Short description of the stock')
            quantity =    IntField('Quantity of stocks')
            unitprice =   DecimalField('Buy price of one stock')
            unitvalue =   DecimalField('Current value of one stock')
            valuation =   DecimalField('Total current valuation of the Investment')
            diff =        DecimalField('Difference between the buy cost and the current valuation')

            '''

            inv = Investment()
            isin = self.get_isin(link)

            if isin:
                inv.id = inv.code = isin
            inv.label = cells[0]
            inv.quantity = Decimal(cells[3])
            inv.valuation = Decimal(cells[4])
            inv.unitprice = Decimal(cells[5])
            inv.unitvalue = Decimal(cells[2])
            inv.diff = Decimal(cells[6])

            inv._detail_url = link if '/cours.phtml' in link else None

            yield inv
Exemple #25
0
    def iter_investment(self):
        for tr in self.document.xpath(u'//table[@class="boursedetail"]/tr[@class and not(@class="total")]'):

            inv = Investment()
            libelle = self.parser.tocleanstring(tr.xpath('./td[1]')[0]).split(' ')
            inv.label, inv.code = self.split_label_code(libelle)
            diff = self.parse_decimal(tr.xpath('./td[6]')[0])
            inv.quantity = self.parse_decimal(tr.xpath('./td[2]')[0])
            inv.unitvalue = self.parse_decimal(tr.xpath('./td[3]')[0])
            inv.unitprice = self.calc(inv.unitvalue, diff)
            inv.valuation = self.parse_decimal(tr.xpath('./td[5]')[0])
            inv.diff = self.get_diff(inv.valuation, self.calc(inv.valuation, diff))

            yield inv
Exemple #26
0
    def iter_investment(self):
        for tr in self.document.xpath(u'//table[@class="boursedetail"]/tr[@class and not(@class="total")]'):

            inv = Investment()
            libelle = self.parser.tocleanstring(tr.xpath('./td[1]')[0]).split(' ')
            inv.label, inv.code = self.split_label_code(libelle)
            diff = self.parse_decimal(tr.xpath('./td[6]')[0])
            inv.quantity = self.parse_decimal(tr.xpath('./td[2]')[0])
            inv.unitvalue = self.parse_decimal(tr.xpath('./td[3]')[0])
            inv.unitprice = self.calc(inv.unitvalue, diff)
            inv.valuation = self.parse_decimal(tr.xpath('./td[5]')[0])
            inv.diff = self.get_diff(inv.valuation, self.calc(inv.valuation, diff))

            yield inv
 def get_investments(self, link):
     invests = []
     doc = self.browser.get_document(self.browser.openurl(link))
     for table in doc.xpath('//div[@class="block" and not(@style)]//table'):
         for tr in table.xpath('./tr')[1:]:
             tds = tr.xpath('./td')
             inv = Investment()
             inv.label = self.parser.tocleanstring(tds[0])
             inv.vdate = Date(self.parser.tocleanstring(tds[1]))
             inv.unitprice = Decimal(tds[2])
             inv.quantity = Decimal(tds[3])
             inv.valuation = Decimal(tds[4])
             invests.append(inv)
     return invests
Exemple #28
0
    def get_investment(self):
        Decimal = CleanDecimal(replace_dots=True).filter

        for tr in self._tr_list(self.document):
            cells = [el_to_string(td) for td in self._td_list(tr)]
            link = unicode(self._link(tr)[0])
            '''

            Boursorama table cells
            ----------------------

            0. Fonds
            1. Date de valeur
            2. Valeur de part
            3. Nombre de parts
            4. Contre valeur
            5. Prix revient
            6. +/- value en €*
            7. +/- value en %*

            Investment model
            ----------------

            label =       StringField('Label of stocks')
            code =        StringField('Identifier of the stock (ISIN code)')
            description = StringField('Short description of the stock')
            quantity =    IntField('Quantity of stocks')
            unitprice =   DecimalField('Buy price of one stock')
            unitvalue =   DecimalField('Current value of one stock')
            valuation =   DecimalField('Total current valuation of the Investment')
            diff =        DecimalField('Difference between the buy cost and the current valuation')

            '''

            inv = Investment()
            isin = self.get_isin(link)

            if isin:
                inv.id = inv.code = isin
            inv.label = cells[0]
            inv.quantity = Decimal(cells[3])
            inv.valuation = Decimal(cells[4])
            inv.unitprice = Decimal(cells[5])
            inv.unitvalue = Decimal(cells[2])
            inv.diff = Decimal(cells[6])

            inv._detail_url = link if '/cours.phtml' in link else None

            yield inv
Exemple #29
0
    def get_investments(self):
        for line in self.document.xpath('//table[contains(@summary, "Contenu")]/tbody/tr[@class="color4"]'):
            cols1 = line.findall('td')
            cols2 = line.xpath('./following-sibling::tr')[0].findall('td')

            inv = Investment()
            inv.label = self.parser.tocleanstring(cols1[self.COL_LABEL].xpath('.//span')[0])
            inv.code = self.parser.tocleanstring(cols1[self.COL_LABEL].xpath('./a')[0]).split(' ')[-1]
            inv.quantity = self.parse_decimal(cols2[self.COL_QUANTITY])
            inv.unitprice = self.parse_decimal(cols2[self.COL_UNITPRICE])
            inv.unitvalue = self.parse_decimal(cols2[self.COL_UNITVALUE])
            inv.valuation = self.parse_decimal(cols2[self.COL_VALUATION])
            inv.diff = self.parse_decimal(cols2[self.COL_PERF])

            yield inv
Exemple #30
0
    def iter_investment(self):
        for line in self.document.xpath(
                '//table[contains(@class, "ca-data-table")]/descendant::tr[count(td)=8]'
        ):
            cells = line.findall('td')

            inv = Investment()
            inv.label = unicode(cells[self.COL_ID].find('div/a').text.strip())
            inv.code = cells[self.COL_ID].find('div/br').tail.strip()
            inv.quantity = self.parse_decimal(
                cells[self.COL_QUANTITY].find('span').text)
            inv.valuation = self.parse_decimal(cells[self.COL_VALUATION].text)
            inv.diff = self.parse_decimal(cells[self.COL_DIFF].text_content())
            if "%" in cells[self.COL_UNITPRICE].text and "%" in cells[
                    self.COL_UNITVALUE].text:
                inv.unitvalue = inv.valuation / inv.quantity
                inv.unitprice = (inv.valuation - inv.diff) / inv.quantity
            else:
                inv.unitprice = self.parse_decimal(
                    cells[self.COL_UNITPRICE].text)
                inv.unitvalue = self.parse_decimal(
                    cells[self.COL_UNITVALUE].text)

            yield inv
Exemple #31
0
    def iter_investment(self):
        for line in self.document.xpath(
                '//table[contains(@class, "ca-data-table")]/descendant::tr[count(td)>=7]'
        ):
            for sub in line.xpath('./td[@class="info-produit"]'):
                sub.drop_tree()
            cells = line.findall('td')

            if cells[self.COL_ID].find('div/a') is None:
                continue
            inv = Investment()
            inv.label = unicode(cells[self.COL_ID].find('div/a').text.strip())
            inv.code = cells[self.COL_ID].find('div/br').tail.strip().split(
                u'\xa0')[0]
            inv.quantity = self.parse_decimal(
                cells[self.COL_QUANTITY].find('span').text)
            inv.valuation = self.parse_decimal(cells[self.COL_VALUATION].text)
            inv.diff = self.parse_decimal(cells[self.COL_DIFF].text_content())
            if "%" in cells[self.COL_UNITPRICE].text and "%" in cells[
                    self.COL_UNITVALUE].text:
                inv.unitvalue = inv.valuation / inv.quantity
                inv.unitprice = (inv.valuation - inv.diff) / inv.quantity
            else:
                inv.unitprice = self.parse_decimal(
                    cells[self.COL_UNITPRICE].text)
                inv.unitvalue = self.parse_decimal(
                    cells[self.COL_UNITVALUE].text)
            date = cells[self.COL_UNITVALUE].find('span').text
            if ':' in date:
                inv.vdate = ddate.today()
            else:
                day, month = map(int, date.split('/', 1))
                date_guesser = LinearDateGuesser()
                inv.vdate = date_guesser.guess_date(day, month)

            yield inv
Exemple #32
0
    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
Exemple #33
0
    def create_investment(self, cells):
        inv = Investment()
        inv.quantity = MyDecimal('.')(cells[self.COL_QUANTITY])
        inv.unitvalue = MyDecimal('.')(cells[self.COL_UNITVALUE])
        inv.unitprice = NotAvailable
        inv.valuation = MyDecimal('.')(cells[self.COL_VALUATION])
        inv.diff = NotAvailable

        link = cells[self.COL_LABEL].xpath('a[contains(@href, "CDCVAL=")]')[0]
        m = re.search('CDCVAL=([^&]+)', link.attrib['href'])
        if m:
            inv.code = m.group(1)
        else:
            inv.code = NotAvailable
        return inv
Exemple #34
0
    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
Exemple #35
0
    def create_investement(self, cells):
        inv = Investment()
        inv.quantity = self.parse_decimal(cells[self.COL_QUANTITY])
        inv.unitvalue = self.parse_decimal(cells[self.COL_UNITVALUE])
        inv.unitprice = NotAvailable
        inv.valuation = self.parse_decimal(cells[self.COL_VALUATION])
        inv.diff = NotAvailable

        link = cells[self.COL_LABEL].xpath('a[contains(@href, "CDCVAL=")]')[0]
        m = re.search('CDCVAL=([^&]+)', link.attrib['href'])
        if m:
            inv.code = m.group(1)
        else:
            inv.code = NotAvailable
        return inv
Exemple #36
0
    def iter_investment(self, account, invs=None):
        if account.id not in self.investments and invs is not None:
            self.investments[account.id] = []
            for inv in invs:
                i = Investment()
                i.label = "%s - %s" % (inv['classification'], inv['description'])
                i.code = inv['isin']
                i.quantity = CleanDecimal().filter(inv['nombreParts'])
                i.unitprice = CleanDecimal().filter(inv['prixMoyenAchat'])
                i.unitvalue = CleanDecimal().filter(inv['valeurCotation'])
                i.valuation = CleanDecimal().filter(inv['montantEuro'])
                i.vdate = Date().filter(inv['datePosition'])
                i.diff = CleanDecimal().filter(inv['performanceEuro'])

                self.investments[account.id].append(i)
        return self.investments[account.id]
Exemple #37
0
    def iter_investment(self, account, invs=None):
        if account.id not in self.investments and invs is not None:
            self.investments[account.id] = []
            for inv in invs:
                i = Investment()
                i.label = "%s - %s" % (inv['classification'], inv['description'])
                i.code = inv['isin']
                i.code_type = Investment.CODE_TYPE_ISIN
                i.quantity = CleanDecimal().filter(inv['nombreParts'])
                i.unitprice = CleanDecimal().filter(inv['prixMoyenAchat'])
                i.unitvalue = CleanDecimal().filter(inv['valeurCotation'])
                i.valuation = CleanDecimal().filter(inv['montantEuro'])
                i.vdate = Date().filter(inv['datePosition'])
                i.diff = CleanDecimal().filter(inv['performanceEuro'])

                self.investments[account.id].append(i)
        return self.investments[account.id]
Exemple #38
0
    def get_investments(self):
        for line in self.document.xpath(
                '//table[contains(@summary, "Contenu")]/tbody/tr[@class="color4"]'
        ):
            cols1 = line.findall('td')
            cols2 = line.xpath('./following-sibling::tr')[0].findall('td')

            inv = Investment()
            inv.label = self.parser.tocleanstring(
                cols1[self.COL_LABEL].xpath('.//span')[0])
            inv.code = self.parser.tocleanstring(
                cols1[self.COL_LABEL].xpath('./a')[0]).split(' ')[-1]
            inv.quantity = self.parse_decimal(cols2[self.COL_QUANTITY])
            inv.unitprice = self.parse_decimal(cols2[self.COL_UNITPRICE])
            inv.unitvalue = self.parse_decimal(cols2[self.COL_UNITVALUE])
            inv.valuation = self.parse_decimal(cols2[self.COL_VALUATION])
            inv.diff = self.parse_decimal(cols2[self.COL_PERF])

            yield inv
Exemple #39
0
    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), 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
Exemple #40
0
    def iter_investment(self):
        for tr in self.doc.xpath(
                u'//table[@class="boursedetail"]/tr[@class and not(@class="total")]'
        ):

            inv = Investment()
            libelle = CleanText('.')(tr.xpath('./td[1]')[0]).split(' ')
            inv.label, inv.code = self.split_label_code(libelle)
            diff = self.parse_decimal(tr.xpath('./td[6]')[0])
            inv.quantity = self.parse_decimal(tr.xpath('./td[2]')[0])
            inv.unitvalue = self.parse_decimal(tr.xpath('./td[3]')[0])
            date = CleanText('.')(tr.xpath('./td[4]')[0])
            inv.vdate = Date(dayfirst=True).filter(
                date) if date and date != '-' else NotAvailable
            inv.unitprice = self.calc(inv.unitvalue, diff)
            inv.valuation = self.parse_decimal(tr.xpath('./td[5]')[0])
            inv.diff = self.get_diff(inv.valuation,
                                     self.calc(inv.valuation, diff))

            yield inv
Exemple #41
0
    def iter_investment(self, account, invs=None):
        if account.id not in self.investments and invs is not None:
            self.investments[account.id] = []
            for inv in invs:
                i = Investment()
                # If nothing is given to make the label, we use the ISIN instead
                # We let it crash if the ISIN is not available either.
                if all([inv['classification'], inv['description']]):
                    i.label = "%s - %s" % (inv['classification'],
                                           inv['description'])
                else:
                    i.label = Coalesce().filter((
                        inv['classification'],
                        inv['description'],
                        inv['isin'],
                    ))
                i.code = inv['isin']
                if not is_isin_valid(i.code):
                    i.code = NotAvailable
                    i.code_type = NotAvailable
                    if u'Solde Espèces' in i.label:
                        i.code = 'XX-liquidity'
                else:
                    i.code_type = Investment.CODE_TYPE_ISIN

                i.quantity = CleanDecimal(default=NotAvailable).filter(
                    inv['nombreParts'])
                i.unitprice = CleanDecimal(default=NotAvailable).filter(
                    inv['prixMoyenAchat'])
                i.unitvalue = CleanDecimal(default=NotAvailable).filter(
                    inv['valeurCotation'])
                i.valuation = CleanDecimal().filter(inv['montantEuro'])
                # For some invests the vdate returned is None
                # Consequently we set the default value at NotAvailable
                i.vdate = Date(default=NotAvailable).filter(
                    inv['datePosition'])
                i.diff = CleanDecimal(default=NotAvailable).filter(
                    inv['performanceEuro'])

                self.investments[account.id].append(i)
        return self.investments[account.id]
Exemple #42
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        #popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY &euro;#YY,YY &euro;#1 YYY,YY &euro;#-YYY,YY &euro;#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&amp;pl=6&amp;nc=1&amp;
        #popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY &euro;#YY,YYY &euro;#YYY,YY &euro;#YY,YY &euro;#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&amp;pl=6&amp;nc=1&amp;
        # [...]
        lines = self.document.split("popup=2")
        lines.pop(0)
        for line in lines:
            columns = line.split('#')
            code = columns[0].split('{')[2]
            invest = Investment(code)
            invest.code = code
            invest.label = columns[0].split('{')[-1]
            invest.quantity = int(columns[1])
            invest.unitprice = Decimal(FrenchTransaction.clean_amount(columns[2]))
            invest.unitvalue = Decimal(FrenchTransaction.clean_amount(columns[3]))
            invest.valuation = Decimal(FrenchTransaction.clean_amount(columns[4]))
            invest.diff = Decimal(FrenchTransaction.clean_amount(columns[5]))

            yield invest
Exemple #43
0
    def iter_investment(self):
        table = self.document.xpath('//table[@align="center"]')[4]
        rows = table.xpath('.//tr[@class="hdoc1"]')
        for tr in rows:
            cells = clean_cells(tr.findall('td'))
            cells[2:] = clean_amounts(cells[2:])

            inv = Investment()
            inv.label, _, inv.quantity, inv.unitvalue, inv.valuation = cells

            tr2 = tr.xpath('./following-sibling::tr')[0]
            tr2td = tr2.findall('td')[1]

            inv.id = inv.code = clean_text(tr2.xpath('.//a')[0])
            inv.unitprice = clean_amount(tr2td.xpath('.//td[@class="hdotc1nb"]')[0].text)

            inv.description = u''
            if inv.unitprice:
                inv.diff = inv.quantity * inv.unitprice - inv.valuation

            yield inv
Exemple #44
0
    def get_investment(self):
        for tr in self.document.xpath('//table[@id="liste-positions-engagements"]/tbody/tr'):
            cells = tr.xpath('./td')

            if len(cells) < 6:
                continue

            inv = Investment()
            inv.label = self.parser.tocleanstring(cells[0].xpath('.//a')[0])
            isin_div = cells[0].xpath('.//div')
            if len(isin_div) > 0:
                inv.id = inv.code = self.parser.tocleanstring(isin_div[0])

            inv.quantity = Decimal(cells[1])
            # <td data-header="Cours">20,650<br>(<span class="varup">+0,54%</span>)</td>
            inv.unitprice = Decimal(cells[2].xpath('text()')[0])
            inv.unitvalue = Decimal(cells[3].xpath('text()')[0])
            inv.valuation = Decimal(cells[4])
            inv.diff = Decimal(cells[5])
            inv._detail_url = None

            yield inv
Exemple #45
0
    def iter_investment(self):
        table = self.document.xpath('//table[@align="center"]')[4]
        rows = table.xpath('.//tr[@class="hdoc1"]')
        for tr in rows:
            cells = clean_cells(tr.findall('td'))
            cells[2:] = clean_amounts(cells[2:])

            inv = Investment()
            inv.label, _, inv.quantity, inv.unitvalue, inv.valuation = cells

            tr2 = tr.xpath('./following-sibling::tr')[0]
            tr2td = tr2.findall('td')[1]

            inv.id = inv.code = clean_text(tr2.xpath('.//a')[0])
            inv.unitprice = clean_amount(
                tr2td.xpath('.//td[@class="hdotc1nb"]')[0].text)

            inv.description = u''
            if inv.unitprice:
                inv.diff = inv.quantity * inv.unitprice - inv.valuation

            yield inv
Exemple #46
0
    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
Exemple #47
0
    def iter_investments(self):
        # We did not get some html, but something like that (XX is a quantity, YY a price):
        # message='[...]
        # popup=2{6{E:ALO{PAR{{reel{695{380{ALSTOM REGROUPT#XX#YY,YY &euro;#YY,YY &euro;#1 YYY,YY &euro;#-YYY,YY &euro;#-42,42%#-0,98 %#42,42 %#|1|AXA#cotationValeur.php?val=E:CS&amp;pl=6&amp;nc=1&amp;
        # popup=2{6{E:CS{PAR{{reel{695{380{AXA#XX#YY,YY &euro;#YY,YYY &euro;#YYY,YY &euro;#YY,YY &euro;#3,70%#42,42 %#42,42 %#|1|blablablab #cotationValeur.php?val=P:CODE&amp;pl=6&amp;nc=1&amp;
        # [...]
        lines = self.doc.split("popup=2")
        lines.pop(0)
        invests = []
        for line in lines:
            columns = line.split('#')
            _pl = columns[0].split('{')[1]
            _id = columns[0].split('{')[2]
            invest = Investment(_id)
            invest.label = unicode(columns[0].split('{')[-1])
            invest.code = unicode(_id)
            if ':' in invest.code:
                invest.code = self.browser.titrevalue.open(val=invest.code,
                                                           pl=_pl).get_isin()
            # The code we got is not a real ISIN code.
            if not re.match(
                    '^[A-Z]{2}[\d]{10}$|^[A-Z]{2}[\d]{5}[A-Z]{1}[\d]{4}$',
                    invest.code):
                m = re.search(
                    '\{([A-Z]{2}[\d]{10})\{|\{([A-Z]{2}[\d]{5}[A-Z]{1}[\d]{4})\{',
                    line)
                if m:
                    invest.code = unicode(m.group(1) or m.group(2))

            quantity = FrenchTransaction.clean_amount(columns[1])
            invest.quantity = CleanDecimal(
                default=NotAvailable).filter(quantity)

            unitprice = FrenchTransaction.clean_amount(columns[2])
            invest.unitprice = CleanDecimal(
                default=NotAvailable).filter(unitprice)

            unitvalue = FrenchTransaction.clean_amount(columns[3])
            invest.unitvalue = CleanDecimal(
                default=NotAvailable).filter(unitvalue)

            valuation = FrenchTransaction.clean_amount(columns[4])
            # valuation is not nullable, use 0 as default value
            invest.valuation = CleanDecimal(
                default=Decimal('0')).filter(valuation)

            diff = FrenchTransaction.clean_amount(columns[5])
            invest.diff = CleanDecimal(default=NotAvailable).filter(diff)

            # On some case we have a multine investment with a total column
            # for now we have only see this on 2 lines, we will need to adapt it when o
            if columns[9] == u'|Total' and _id == 'fichevaleur':
                prev_inv = invest
                invest = invests.pop(-1)
                if prev_inv.quantity:
                    invest.quantity = invest.quantity + prev_inv.quantity
                if prev_inv.valuation:
                    invest.valuation = invest.valuation + prev_inv.valuation
                if prev_inv.diff:
                    invest.diff = invest.diff + prev_inv.diff

            invests.append(invest)

        for invest in invests:
            yield invest
Exemple #48
0
    def iter_investment(self):
        not_rounded_valuations = self.get_not_rounded_valuations()

        doc = self.browser.open('/brs/fisc/fisca10a.html').page.doc
        num_page = None

        try:
            num_page = int(
                CleanText('.')(doc.xpath(
                    u'.//tr[contains(td[1], "Relevé des plus ou moins values latentes")]/td[2]'
                )[0]).split('/')[1])
        except IndexError:
            pass

        docs = [doc]

        if num_page:
            for n in range(2, num_page + 1):
                docs.append(
                    self.browser.open(
                        '%s%s' % ('/brs/fisc/fisca10a.html?action=12&numPage=',
                                  str(n))).page.doc)

        for doc in docs:
            # There are two different tables possible depending on the market account type.
            is_detailed = bool(
                doc.xpath(
                    u'//span[contains(text(), "Années d\'acquisition")]'))
            tr_xpath = '//tr[@height and td[@colspan="6"]]' if is_detailed else '//tr[count(td)>5]'
            for tr in doc.xpath(tr_xpath):
                cells = tr.findall('td')

                inv = Investment()

                title_split = cells[self.COL_LABEL].xpath(
                    './/span')[0].attrib['title'].split(' - ')
                inv.label = unicode(title_split[0])

                for code in title_split[1:]:
                    if len(code) == 12:
                        inv.code = unicode(code)
                        break
                else:
                    inv.code = NotAvailable

                if is_detailed:
                    inv.quantity = MyDecimal('.')(
                        tr.xpath('./following-sibling::tr/td[2]')[0])
                    inv.unitprice = MyDecimal('.', replace_dots=True)(
                        tr.xpath('./following-sibling::tr/td[3]')[1])
                    inv.unitvalue = MyDecimal('.', replace_dots=True)(
                        tr.xpath('./following-sibling::tr/td[3]')[0])

                    try:  # try to get not rounded value
                        inv.valuation = not_rounded_valuations[inv.label]
                    except KeyError:  # ok.. take it from the page
                        inv.valuation = MyDecimal('.')(
                            tr.xpath('./following-sibling::tr/td[4]')[0])

                    inv.diff = MyDecimal('.')(tr.xpath('./following-sibling::tr/td[5]')[0]) or \
                               MyDecimal('.')(tr.xpath('./following-sibling::tr/td[6]')[0])
                else:
                    inv.quantity = MyDecimal('.')(cells[self.COL_QUANTITY])
                    inv.diff = MyDecimal('.')(cells[self.COL_DIFF])
                    inv.unitprice = MyDecimal('.')(
                        cells[self.COL_UNITPRICE].xpath('.//tr[1]/td[2]')[0])
                    inv.unitvalue = MyDecimal('.')(
                        cells[self.COL_VALUATION].xpath('.//tr[1]/td[2]')[0])
                    inv.valuation = MyDecimal('.')(
                        cells[self.COL_VALUATION].xpath('.//tr[2]/td[2]')[0])

                yield inv