Exemplo n.º 1
0
def getDetails(enterprise):
    logging.info('Getting Details of Company %s', enterprise[0])

    edp,name = enterprise[0],enterprise[1]
    d = dict()
    d['id'] = edp
    d['name'] = name
    d['register_date'] = datetime.now().isoformat()
    page = openUrl(buildUrl(URL_EDETAIL, 'CodCVM=' + edp))

    # Company Data
    att = getTables(page, 'panel1a')
    for table in att[:3]:
        for row in getRows(table): rowToDict(row,d)

    #print tostring(page)
    att = HtmlElement(page).get_element_by_id('panel1a')
    d['trading_codes'] = [ l.text for l in HtmlElement(att).find_class('LinkCodNeg') ]
    att = d['industry_classification'].split('/')
    d['sector'] = att[0].strip()
    d['subsector'] = att[1].strip()
    d['segment'] = att[2].strip()
    d['detailwebsite'] = buildUrl(URL_RESUMO, 'codigoCvm=' + edp, 'idioma=pt-BR')
    if 'website' in d: d['website'] = urlparse.urlsplit(d['website'], 'http').geturl()

    return d
Exemplo n.º 2
0
def getDfpConBPA(url, infos):
    logging.info('Getting DFs Consolidadas - Balanco Patrimonial Ativo')
    t = dict()
    page = HtmlElement(openUrl(url)) 
    table = page.get_element_by_id(TABLE_BPP)
    for row in getRows(table): rowToDict(row, t)

    # Multiplicador
    m = getMultiplicador(page)

    # Caixa
    cxa = toInt(t['1.01.01'][1])*m if '1.01.01' in t else 0
    apf = toInt(t['1.01.02'][1])*m if '1.01.02' in t else 0
    infos['CAIXA'] = cxa + apf
Exemplo n.º 3
0
def getDftDemRes(url, infos):
    logging.info('Getting DFs Consolidadas - Demonstracao do Resultado')
    t = dict()
    page = openUrl(url) 
    table = HtmlElement(page).get_element_by_id(TABLE_BPP)
    for row in getRows(table): rowToDict(row, t)

    # Multiplicador
    m = getMultiplicador(page)

    # Receita Liquida
    infos['RL'] = toInt(t['3.01'][1])*m if '3.01' in t else 0
    # Lucro Liquito
    infos['LL'] = next((toInt(v[1])*m for k,v in t.iteritems() if re.match('^Lucro.+odo$', v[0])), 0)
Exemplo n.º 4
0
def getDftDemRes(nsd, nsr, infos, params_geral=PARMS_GERAL):
    logging.info('Getting DFs Consolidadas - Demonstracao do Resultado - %s %s', nsd, nsr)
    t = dict()
    page = openUrl(buildUrl(URL_FDF, params_geral, PARMS_BPP, 
        'NumeroSequencialDocumento=' + nsd, 'NumeroSequencialRegistroCvm=' + nsr, 
        'Informacao=2', 'Demonstracao=4'))
    table = HtmlElement(page).get_element_by_id(TABLE_BPP)
    for row in getRows(table): rowToDict(row, t)

    # Multiplicador
    m = getMultiplicador(page)

    # Receita Liquida
    infos['RL'] = toInt(t['3.01'][1])*m if '3.01' in t else 0
    # Lucro Liquito
    infos['LL'] = toInt(t['3.11'][1])*m if '3.11' in t else 0
Exemplo n.º 5
0
def getDfpConBPA(nsd, nsr, infos):
    logging.info('Getting DFs Consolidadas - Balanco Patrimonial Ativo - %s %s', nsd, nsr)
    t = dict()
    page = HtmlElement(openUrl(buildUrl(URL_FDF, PARMS_GERAL, PARMS_BPP, 
        'NumeroSequencialDocumento=' + nsd, 'NumeroSequencialRegistroCvm=' + nsr, 
        'Informacao=2', 'Demonstracao=2')))
    table = page.get_element_by_id(TABLE_BPP)
    for row in getRows(table): rowToDict(row, t)

    # Multiplicador
    m = getMultiplicador(page)

    # Caixa
    cxa = toInt(t['1.01.01'][1])*m if '1.01.01' in t else 0
    apf = toInt(t['1.01.02'][1])*m if '1.01.02' in t else 0
    infos['CAIXA'] = cxa + apf
Exemplo n.º 6
0
def calcCDBDIUpdateValue(dt_from, dt_to, rate, value):
    d = {
        'DT_DIA_DE': str(dt_from.day),
        'DT_MES_DE': str(dt_from.month),
        'DT_ANO_DE': str(dt_from.year),
        'DT_DIA_ATE': str(dt_to.day),
        'DT_MES_ATE': str(dt_to.month),
        'DT_ANO_ATE': str(dt_to.year),
        'var_perc': "{0:.2f}".format(rate * 100).replace(".", ","),
        'var_valor': "{0:.2f}".format(value).replace(".", ","),
        'var_indice': str(3),
        'var_idioma': str(1)
    }
    r = requests.post(URL_CALCDI, data=d)
    page = etree.HTML(r.content)
    tables = page.findall('.//table') 
    upvalue = next((row[1] for row in getRows(tables[0]) if row[0] == 'Valor Atualizado:'))
    return float(upvalue.replace('.', '').replace(',', '.'))
Exemplo n.º 7
0
def getDfpConBPP(nsd, nsr, infos):
    logging.info('Getting DFs Consolidadas - Balanco Patrimonial Passivo - %s %s', nsd, nsr)
    t = dict()
    page = openUrl(buildUrl(URL_FDF, PARMS_GERAL, PARMS_BPP, 
        'NumeroSequencialDocumento=' + nsd, 'NumeroSequencialRegistroCvm=' + nsr, 
        'Informacao=2', 'Demonstracao=3'))
    table = HtmlElement(page).get_element_by_id(TABLE_BPP)
    for row in getRows(table): rowToDict(row, t)

    # Multiplicador
    m = getMultiplicador(page)

    # Patrimonio Liquido
    infos['PL'] = toInt(t['2.03'][1])*m if '2.03' in t else 0
    # Divida Bruta
    CP = toInt(t['2.01.04'][1])*m if '2.01.04' in t else 0
    LP = toInt(t['2.02.01'][1])*m if '2.02.01' in t else 0
    infos['DB'] = CP + LP
Exemplo n.º 8
0
def getDfpConBPP(url, infos):
    logging.info('Getting DFs Consolidadas - Balanco Patrimonial Passivo')
    t = dict()
    page = openUrl(url) 
    table = HtmlElement(page).get_element_by_id(TABLE_BPP)
    for row in getRows(table): rowToDict(row, t)

    # Multiplicador
    m = getMultiplicador(page)

    # Patrimonio Liquido
    infos['PL'] = toInt(t['2.03'][1])*m if '2.03' in t else 0
    # Divida Bruta
    CP = toInt(t['2.01.04'][1])*m if '2.01.04' in t else 0
    LP = toInt(t['2.02.01'][1])*m if '2.02.01' in t else 0
    infos['DB'] = CP + LP
    # Dividendos
    Div = toInt(t['2.01.05.02.01'][1])*m if '2.01.05.02.01' in t else 0
    infos['DIV'] = Div
Exemplo n.º 9
0
    parser.add_argument('-f', dest='filename', help='filename str', default='')
    parser.add_argument('--host', dest='host',
                        help='db ip/hostname', default='127.0.0.1')
    parser.add_argument('--port', dest='port', help='db port', default=3306)
    parser.add_argument('--user', dest='user', help='db user', default='')
    parser.add_argument('--passwd', dest='passwd',
                        help='db passwd', default='')
    parser.add_argument('--db', dest='db', help='db database', default='dots')
    args = parser.parse_args()

    try:
        conn = MySQLdb.connect(
            host=args.host, port=args.port, user=args.user, passwd=args.passwd, db=args.db)
        cur = conn.cursor()

        ids = utils.getRows(cur, col='id', table='blocker')
        i = int(args.id)

        if args.method == "get":
            if i in ids:
                b = [getBlocker(i, cur)]
            elif ids:
                b = [getBlocker(i, cur) for i in ids]
            blockers = {'blocker': b}
            utils.printYamlDump(blockers)

        elif args.method == "set":
            blockers = utils.fileYamlLoad(args.filename)
            for d in blockers['blocker']:
                if d['id'] not in ids:
                    setBlocker(d, cur)