Exemplo n.º 1
0
def published_econ_agri_indic(content):
    # Retorna a tabela de indicadores extraída do arquivo txt do site da bovespa
    cont_list = content.split('\n')
    cont_list.pop(len(cont_list) - 1)
    parseStr = lambda x: x.isalpha() and x or x.isdigit() and \
     int(x) or x.isalnum() and x or \
     len(set(string.punctuation).intersection(x)) == 1 and \
     x.count('.') == 1 and float(x) or x

    table = [i for i in cont_list]
    for i in range(0, len(cont_list)):
        table[i] = [
            cont_list[i][0:6], cont_list[i][6:9], cont_list[i][9:11],
            parsers.dateISOer(cont_list[i][11:19]), cont_list[i][19:21],
            cont_list[i][21:46].strip(),
            str(
                DefaultContext.divide(
                    Decimal(parseStr(cont_list[i][47:71])),
                    DefaultContext.power(
                        Decimal('10'),
                        Decimal(parseStr(cont_list[i][71:73]))))),
            cont_list[i][71:73]
        ]
    #'''
    last_biz_day = bd.Calendar('ANBIMA').offset(date.today().isoformat(), -1)
    f = open('IndicRelatorio' + last_biz_day + '.txt', 'w+')
    for m, i in enumerate(table):
        for k, j in enumerate(table[m]):
            f.write(table[m][k] + ',')
        f.write('\n')
    f.close()
    #'''
    return dict(id='BOLETIM_ECON_AGRO',
                date=parsers.dateISOer(cont_list[1][11:19]),
                indic=table)
Exemplo n.º 2
0
def published_selic(content):
    selic = {}
    selic['id'] = 'SELIC'
    selic['value'] = re.findall('SELIC: (\d*.\d*)% ao ano', content)[0]
    selic['value'] = selic['value'].replace(',', '.')
    selic['date'] = parsers.dateISOer(
        re.findall('SELIC: \d*.\d*% ao ano \*[^\*]*\*Em (\d*.\d*.\d*)',
                   content)[0])
    return selic
Exemplo n.º 3
0
def published_options(content):

    cont_list = content.split('\n')
    cont_list.pop(len(cont_list) - 1)  # retira a linha vazia criada no split()

    # O Cabeçalho e o Rodapé possuem formatos diferentes
    header = []
    header = [
        cont_list[0][:2], cont_list[0][2:15], cont_list[0][15:23],
        cont_list[0][23:31]
    ]

    footer = []
    footer = [
        cont_list[len(cont_list) - 1][:2], cont_list[len(cont_list) - 1][2:15],
        cont_list[len(cont_list) - 1][15:23],
        cont_list[len(cont_list) - 1][23:31],
        cont_list[len(cont_list) - 1][31:42]
    ]

    # Cria a lista com a mesma qtd de elementos da lista final
    table = [i for i in cont_list]

    # Cria lista com as linhas cortadas no campo correto segundo o arq de layout da bm&f bovespa
    for i in range(0, len(cont_list)):
        if i == 0:
            table[i] = header
        else:
            if i == len(cont_list) - 1:
                table[i] = footer
            else:
                table[i] = [
                    cont_list[i][0:2], cont_list[i][2:10], cont_list[i][10:12],
                    cont_list[i][12:24], cont_list[i][24:27],
                    cont_list[i][27:39], cont_list[i][39:49],
                    cont_list[i][49:52], cont_list[i][52:56],
                    cont_list[i][56:69], cont_list[i][69:82],
                    cont_list[i][82:95], cont_list[i][95:108],
                    cont_list[i][108:121], cont_list[i][121:134],
                    cont_list[i][134:147], cont_list[i][147:152],
                    cont_list[i][152:170], cont_list[i][170:188],
                    cont_list[i][188:201], cont_list[i][201:202],
                    cont_list[i][202:210], cont_list[i][210:217],
                    cont_list[i][217:230], cont_list[i][230:242],
                    cont_list[i][242:245]
                ]
    # Extrai apenas os códigos de opções de compra e venda, exceto do header e do footer.
    options = [
        i for j, i in enumerate(table)
        if j not in [0, len(table) -
                     1] and (table[j][4] == '070' or table[j][4] == '080')
    ]

    return dict(id='BOLETIM_OPCOES',
                date=parsers.dateISOer(header[3]),
                opt=options)
Exemplo n.º 4
0
def published_ipca_pro_rata(content):
    ipca = {}
    ipca['id'] = 'IPCA_PRO_RATA'
    ipca['date'] = parsers.dateISOer(
        re.findall('IPCA.* pro rata em.* (\d*/\d*/\d)*.*= \d*.\d*,\d*',
                   content)[0])
    ipca['value'] = re.findall(
        'IPCA.* pro rata em.* \d*/\d*/\d*.*= (\d*.\d*,\d*)', content)[0]
    ipca['value'] = ipca['value'].replace('.', '').replace(',', '.')
    return ipca
Exemplo n.º 5
0
def published_igpm_pro_rata(content):
    igpm = {}
    igpm['id'] = 'IGPM_PRO_RATA'
    igpm['date'] = parsers.dateISOer(
        re.findall('IGP-M.* pro rata em.* (\d*/\d*/\d)*.*= \d*,\d*',
                   content)[0])
    igpm['value'] = re.findall(
        'IGP-M.* pro rata em.* \d*/\d*/\d*.*= (\d*,\d*)', content)[0]
    igpm['value'] = igpm['value'].replace(',', '.')
    return igpm
Exemplo n.º 6
0
def published_ipca_index(content):
    ipca = {}
    ipca['id'] = 'IPCA_ANBIMA_INDICE'
    ipca['date'] = parsers.dateISOer(
        re.findall('\*Expectativa IPCA.*para[^\d]*(\d*.\d*.\d*)', content)[0])
    ipca['value'] = re.findall(
        'tabelaTitulo.*Tarifa.*Valores de Refer.*[^I]*IGP-M.*\d*,\d*.*[^I]*IPCA.* (\d*.\d*,\d*)',
        content)[0]
    ipca['value'] = ipca['value'].replace('.', '').replace(',', '.')
    return ipca
Exemplo n.º 7
0
def published_igpm_index(content):
    igpm = {}
    igpm['id'] = 'IGPM_ANBIMA_INDICE'
    igpm['date'] = parsers.dateISOer(
        re.findall('\*Expectativa IGP-M.*para[^\d]*(\d*.\d*.\d*)', content)[0])
    igpm['value'] = re.findall(
        'tabelaTitulo.*Tarifa.*Valores de Refer.*[^I]*IGP-M.* (\d*,\d*)',
        content)[0]
    igpm['value'] = igpm['value'].replace(',', '.')
    return igpm
Exemplo n.º 8
0
def published_ipca(content):
    ipca = {}
    ipca['id'] = 'IPCA_ANBIMA'
    ipca['date'] = parsers.dateISOer(
        re.findall('\*Expectativa IPCA.*para[^\d]*(\d*.\d*.\d*)', content)[0])
    ipca['value'] = re.findall(
        '\*Expectativa IPCA.*para[^\d]*\d*.\d*.\d*.*[^\d]* (\d*,\d*)%',
        content)[0]
    ipca['value'] = ipca['value'].replace(',', '.')
    return ipca
Exemplo n.º 9
0
def published_igpm(content):
    igpm = {}
    igpm['id'] = 'IGPM_ANBIMA'
    igpm['date'] = parsers.dateISOer(
        re.findall('\*Expectativa IGP-M.*para[^\d]*(\d*.\d*.\d*)', content)[0])
    igpm['value'] = re.findall(
        '\*Expectativa IGP-M.*para[^\d]*\d*.\d*.\d*.*[^\d]* (\d*.\d*)%',
        content)[0]
    igpm['value'] = igpm['value'].replace(',', '.')
    return igpm
Exemplo n.º 10
0
def published_euro_bce(content):
    euro_bce = {}
    euro_bce['id'] = 'EURO_BCE'
    euro_bce['value'] = re.findall(
        'Taxa de .* US\$.*[^*]*>Em \d*.\d*.\d* = (\d*.\d*).*[^*]*\*.* Banco Central Europeu',
        content)[0]
    euro_bce['value'] = euro_bce['value'].replace(',', '.')
    euro_bce['date'] = parsers.dateISOer(
        re.findall(
            'Taxa de .* US\$.*[^*]*>Em (\d*.\d*.\d*) = \d*.\d*.*[^*]*\*.* Banco Central Europeu',
            content)[0])
    return euro_bce
Exemplo n.º 11
0
def published_cdi_cetip(content):
    cdi_cetip = {}
    cdi_cetip['id'] = 'CDICETIP'
    cdi_cetip['value'] = re.findall(
        'Taxa Referencial de DI / Cetip[^(DI)]*.*: (\d*.\d*)%[^(Em)]*Em \d*.\d*.\d*',
        content)[0]
    cdi_cetip['value'] = cdi_cetip['value'].replace(',', '.')
    cdi_cetip['date'] = parsers.dateISOer(
        re.findall(
            'Taxa Referencial de DI / Cetip[^(DI)]*.*: \d*.\d*%[^(Em)]*Em (\d*.\d*.\d*)',
            content)[0])
    return cdi_cetip