Пример #1
0
def get_data_table(tableName):
    conex = get_conex(dDBI["mod"], dDBI["host"], dDBI["port"], dDBI["user"],
                      dDBI["passwd"], dDBI["db"])
    tabla = etl.fromdb(conex, "SELECT * FROM " + tableName)
    etl.tojson(tabla, "./static/data/" + tableName + '.json')
    conex.close()
    rv = showjson(str(tableName))
    return jsonify(rv)
Пример #2
0
def get_atributosTable(tableName):
    conex = get_conex(dDBI["mod"], dDBI["host"], dDBI["port"], dDBI["user"],
                      dDBI["passwd"], dDBI["db"])
    query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =" + "'" + str(
        tableName) + "'"
    atributos = etl.fromdb(conex, query)
    etl.tojson(atributos, "./static/data/" + tableName + '_atrib.json')
    conex.close()
    rv = showjson(str(tableName) + "_atrib")
    return jsonify(rv)
Пример #3
0
def get_all_atributos():
    conex = get_conex(dDBI["mod"], dDBI["host"], dDBI["port"], dDBI["user"],
                      dDBI["passwd"], dDBI["db"])
    listAtrib = "SELECT COLUMN_NAME,TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA =" + "'" + str(
        dDBI["db"]) + "'"
    allAtributos = etl.fromdb(conex, listAtrib)
    etl.tojson(allAtributos, './static/data/allAtributos.json'
               )  #ACA AGREGAR UN IDENTIFICADOR PARA BASE DE DATOS!!!! OJO
    conex.close()
    myAtributos = showjson('allAtributos')
    return jsonify(myAtributos)
Пример #4
0
def get_all_tables():
    conex = get_conex(dDBI["mod"], dDBI["host"], dDBI["port"], dDBI["user"],
                      dDBI["passwd"], dDBI["db"])
    listTable = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA =" + "'" + str(
        dDBI["db"]) + "'"
    tablas = etl.fromdb(conex, listTable)
    etl.tojson(tablas, './static/data/tablas.json'
               )  #ACA AGREGAR UN IDENTIFICADOR PARA BASE DE DATOS!!!! OJO
    conex.close()
    aTablas = showjson('tablas')
    return jsonify(aTablas)
Пример #5
0
def get_cambiar_valor(cambio):
    conex = get_conex(dDBI["mod"], dDBI["host"], dDBI["port"], dDBI["user"],
                      dDBI["passwd"], dDBI["db"])
    myCambio = cambio.split("_")  #0una vez cambiado 1
    tabla = etl.fromdb(conex, "SELECT * FROM " + myCambio[3])
    tablaCambiada = etl.convert(tabla, str(myCambio[0]), 'replace',
                                str(myCambio[1]), str(myCambio[2]))
    etl.tojson(tablaCambiada, "./static/data/cambiarValor.json")
    conex.close()
    rv = showjson("cambiarValor")
    return jsonify(rv)
Пример #6
0
def get_calculos():
    data = request.get_json()
    calculos = data['calculos']
    try:
        table1 = etl.fromjson('./static/data/tabalaElegidaCalculadora.json')

        campos_y_valores = re.split('\=|\+|\-|\/|\*', calculos)
        campoElegido = campos_y_valores[0].lstrip().rstrip()
        campos_a_operar = campos_y_valores[1:]
        print("Campos a operar:", campos_a_operar)
        print("calculos", calculos)
        #get math symbol
        operaciones = []
        for i in calculos:
            if (i == '+' or i == '-' or i == '/' or i == '*'):
                operaciones.append(i)
        #quito espacios
        for i in range(len(campos_a_operar)):
            campos_a_operar[i] = campos_a_operar[i].lstrip().rstrip()

        #Validacion de datos ------------------------------------------------
        todosValidados = True
        i = 0
        while (todosValidados and i < len(campos_a_operar)):
            if campos_a_operar[i].isdigit() == False:
                todosValidados = validarCampo(table1, campos_a_operar[i])
            i += 1

        #---------------------------------------------------------------------
        if todosValidados:
            #agrego row
            for i in range(len(campos_a_operar)):
                if campos_a_operar[i].isdigit() == False:
                    campos_a_operar[i] = 'row.' + campos_a_operar[i]
            #formulo el eval
            operacion_final = ""
            for i in range(len(operaciones)):
                operacion_final += campos_a_operar[i] + operaciones[i]
            operacion_final += campos_a_operar[len(campos_a_operar) - 1]

            table2 = etl.convert(table1,
                                 campoElegido,
                                 lambda v, row: eval(operacion_final),
                                 pass_row=True)
            #etl.tojson(table2,"./static/data/calculos.json")
            etl.tojson(table2, './static/data/tabalaElegidaCalculadora.json')
            rv = showjson("tabalaElegidaCalculadora")
            return jsonify(rv)
        else:
            return jsonify(False)
    except:
        return jsonify(False)
Пример #7
0
def test_tojson():

    # exercise function
    table = (("foo", "bar"), ("a", 1), ("b", 2), ("c", 2))
    f = NamedTemporaryFile(delete=False)
    tojson(table, f.name)
    result = json.load(f)
    assert len(result) == 3
    assert result[0]["foo"] == "a"
    assert result[0]["bar"] == 1
    assert result[1]["foo"] == "b"
    assert result[1]["bar"] == 2
    assert result[2]["foo"] == "c"
    assert result[2]["bar"] == 2
Пример #8
0
def test_tojson():

    # exercise function
    table = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2))
    f = NamedTemporaryFile(delete=False)
    tojson(table, f.name)
    result = json.load(f)
    assert len(result) == 3
    assert result[0]['foo'] == 'a'
    assert result[0]['bar'] == 1
    assert result[1]['foo'] == 'b'
    assert result[1]['bar'] == 2
    assert result[2]['foo'] == 'c'
    assert result[2]['bar'] == 2
Пример #9
0
def test_tojson():

    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', 2),
             ('c', 2))
    f = NamedTemporaryFile(delete=False, mode='r')
    tojson(table, f.name)
    result = json.load(f)
    assert len(result) == 3
    assert result[0]['foo'] == 'a'
    assert result[0]['bar'] == 1
    assert result[1]['foo'] == 'b'
    assert result[1]['bar'] == 2
    assert result[2]['foo'] == 'c'
    assert result[2]['bar'] == 2
Пример #10
0
def test_json_unicode():

    tbl = ((u'name', u'id'),
           (u'Արամ Խաչատրյան', 1),
           (u'Johann Strauß', 2),
           (u'Вагиф Сәмәдоғлу', 3),
           (u'章子怡', 4),
           )
    tojson(tbl, 'tmp/test_tojson_utf8.json')

    result = json.load(open('tmp/test_tojson_utf8.json'))
    assert len(result) == 4
    for a, b in zip(tbl[1:], result):
        assert a[0] == b['name']
        assert a[1] == b['id']

    actual = fromjson('tmp/test_tojson_utf8.json')
    ieq(tbl, actual)
Пример #11
0
def scrape():
    res = requests.get(BASE_URL)
    doc = html.fromstring(res.content)

    query = {}
    for inp in doc.findall('.//form[@name="toetuse_saajad"]//input'):
        if inp.get('type') == 'submit':
            continue
        query[inp.get('name')] = inp.get('value')

    rows = []
    for option in doc.findall('.//select[@id="meede"]/option'):
        measure = option.get('value')
        if len(measure):
            rows.extend(list(scrape_measure(query, measure)))

    tojson(fromdicts(rows), 'Estonia_scraper_dump.json',
           sort_keys=True, **JSON_FORMAT)
Пример #12
0
def make_runlist():
    sql = '''select DISTINCT Location.PointID from dbo.WaterLevelsContinuous_Pressure
join dbo.Location on Location.PointID = dbo.WaterLevelsContinuous_Pressure.PointID
where dbo.Location.LatitudeDD is not null and dbo.Location.PublicRelease=1
group by Location.PointID
order by Location.PointID'''
    table = petl.fromdb(nm_aquifier_connection(), sql)

    obj = petl.tojson(table, 'record_ids.json', indent=2)
    print(obj)
Пример #13
0
def get_query():
    tipo_db = request.get_json()["tipo1"]
    query = request.get_json()["query1"]
    try:
        conex = get_conex(dDBI["mod"], dDBI["host"], dDBI["port"],
                          dDBI["user"], dDBI["passwd"], dDBI["db"])
        etl_resultado = etl.fromdb(conex, query)
        etl.tojson(etl_resultado, './static/data/sql_query.json'
                   )  #ACA AGREGAR UN IDENTIFICADOR PARA BASE DE DATOS!!!! OJO
        aTablas = showjson('sql_query')
        return jsonify(aTablas)
    except pymysql.err.OperationalError as e:
        s = str(e)
        return jsonify({'query': False, 'err': s})  #False
    except pymysql.err.InternalError as e:
        s = str(e)
        return jsonify({'query': False, 'err': s})  #False
    except pymysql.err.ProgrammingError as e:
        s = str(e)
        return jsonify({'query': False, 'err': s})
Пример #14
0
 def import_write_data(self):
     petl.tojson(self.data, config.weather_data_store_path)
     return True
Пример #15
0
appendsqlite3(moredata, 'test.db', 'foobar') 
# look what it did
from petl import look, fromsqlite3
look(fromsqlite3('test.db', 'select * from foobar'))


# tojson

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tojson, look
look(table)
tojson(table, 'example.json')
# check what it did
with open('example.json') as f:
    print f.read()


# tojsonarrays

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tojsonarrays, look
look(table)
tojsonarrays(table, 'example.json')
Пример #16
0
dicts = [{"foo": "a", "bar": 1},
         {"foo": "b", "bar": 2},
         {"foo": "c", "bar": 2}]
table1 = etl.fromdicts(dicts)
table1


# tojson()
##########

import petl as etl
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
etl.tojson(table1, 'example.json', sort_keys=True)
# check what it did
print(open('example.json').read())


# tojsonarrays()
################

import petl as etl
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
etl.tojsonarrays(table1, 'example.json')
# check what it did
print(open('example.json').read())
Пример #17
0
appendsqlite3(moredata, 'test.db', 'foobar') 
# look what it did
from petl import look, fromsqlite3
look(fromsqlite3('test.db', 'select * from foobar'))


# tojson

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tojson, look
look(table)
tojson(table, 'example.json')
# check what it did
with open('example.json') as f:
    print f.read()


# tojsonarrays

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tojsonarrays, look
look(table)
tojsonarrays(table, 'example.json')
Пример #18
0
def writeDataToJson(path, output):
    etl.tojson(getTable(path), output)
Пример #19
0
def post_asignar():
    data = request.get_json()
    table = etl.fromdicts(data)
    etl.tojson(table, './static/data/tabalaElegidaCalculadora.json')
    return jsonify(True)