Пример #1
0
    def dump_map_to_db(d_map):
        session = Session()
        
        for t in d_map:
            x, y, v = t
            entry = DataMap(x=x, y=y, value=v)
            session.merge(entry)
        session.commit()
    
        

#Base.metadata.create_all(engine)
Пример #2
0
def actualizar_db():
    print("Updating database using the Google Sheets API.")
    session = Session()
    service = setup_service()
    generacional = get_generational(
        service, "1USCGq_T6GfEC2662Z6iRrSzc1AAoMHM4W13ATAvFs54")
    # generacional = [
    #     ["Representación", "Nombre", "7/5/20", "5/6/20", "1/7/20", "4/7/20", "06/8/20"],
    #     ["2020", "Agustín Covarrubias", "P", "P", "P", "P", "P"],
    #     ["2020", "Katherine Catoni", "P", "P", "P", "P", "P"],
    #     ["2020", "Rafael Rencoret", "P", "P", "P", "P", "P"],
    #     ["2019", "Tania Hinostroza", "P", "P", "P", "P", "P"],
    #     ["2019", "Florencia Sciaraffia", "P", "P", "P", "P", "P"],
    #     ["2019", "Martín Illanes", "P", "P", "P", "P", "P"],
    #     ["2018", "Joaquín Castaños", "P", "P", "J", "P", "P"],
    #     ["2018", "Elizabeth Hermosilla", "P", "P", "J", "P", "P"],
    #     ["2018", "Pedro Becker", "P", "P", "P", "P", "P"],
    #     ["2017", "Camila López", "P", "P", "P", "P", "P"],
    #     ["2017", "Francisco Úrzua", "P", "P", "P", "P", "O"],
    #     ["2017", "Bartolomé Peirano", "P", "P", "P", "P", "P"],
    #     ["2016", "Manuel Jara", "P", "P", "P", "P", "P"],
    #     ["2016", "Ivania Arias", "P", "P", "P", "P", "P"],
    #     ["2016", "María Belén Echenique", "P", "P", "P", "P", "P"],
    #     ["2015 y ant.", "Denise Cariaga", "P", "P", "P", "P", "P"],
    #     ["2015 y ant.", "Graciela Hernández", "P", "P", "P", "P", "P"],
    #     ["2015 y ant.", "Caterin Pinto", "P", "P", "P", "P", "O"],
    #     ["CAI", "Isa Oyarzo", "P", "P", "P", "P", "P"],
    #     ["CAI", "Thomas Struszer", "P", "P", "P", "P", "P"],
    #     ["CAI", "Agustín Cox", "P", "P", "P", "P", "P"],
    #     ["CAI", "Claudio Escobar", "P", "P", "P", "P", "P"],
    #     ["CAI", "Javiera Dawabe", "P", "P", "P", "P", "P"],
    #     ["CT", "José Pereira", "P", "P", "P", "A", "P"],
    #     ["CT", "Trinidad Larraín", "P", "P", "P", "P", "A"],
    #     ["CT", "María Ignacia Henriquez", "P", "P", "P", "J", "P"],
    #     ["CT", "Tomás Álvarez", "A", "A", "A", "A", "A"],
    #     ["CT", "Magdalena Merino", "P", "P", "P", "P", "P"],
    # ]

    # academico = get_academic(service, "1ditHP6pQUyAx73t_76csuJUH4t4TPqlRa5CHHWRXz3o")

    fechas_existentes = [
        sesion.fecha for sesion in session.query(SesionConsejo).all()
    ]
    fechas_en_tabla = [convertir_fecha(fecha) for fecha in generacional[0][2:]]
    fechas_por_agregar = [
        fecha for fecha in fechas_en_tabla if fecha not in fechas_existentes
    ]
    tgeneracional = transpose(generacional)
    nombres = tgeneracional[1][1:]
    representaciones = transformar_representaciones(tgeneracional[0][1:])

    sesiones = {}
    representantes = {}
    for indice, nombre in enumerate(nombres):
        representacion = representaciones[indice]
        tipo = representacion[0]
        representa = representacion[1]
        representantes[nombre] = Representante(nombre=nombre,
                                               representa=representa,
                                               tipo=tipo)

    for fecha in fechas_en_tabla:
        sesiones[fecha] = SesionConsejo(fecha=fecha)

    for indice_y, fecha in enumerate(fechas_por_agregar):
        y = indice_y + 2
        for indice_x, representante in enumerate(tgeneracional[indice_y][1:]):
            x = indice_x + 1
            nombre = nombres[x - 1]
            asistio = tgeneracional[y][x]

            representante = representantes[nombre]
            sesion = sesiones[fecha]

            sesion.add_representantes([(representante, asistio)])

    for representante in representantes.values():
        session.merge(representante)

    for sesion in sesiones.values():
        session.merge(sesion)

    session.commit()

    session.close()
Пример #3
0
 def set_stored_value(tile, value):
     x, y = tile
     session = Session()
     entry = DataMap(x=x, y=y, value=value)
     session.merge(entry)    
     session.commit()