Insert in a table from python

0

I have two scripts which I connect to the database and the second extracts information from the database called Timetable.

The first function is called persistence which makes the connection and executes a query in the database and the second script is called extraction as its name indicates it extracts information from the database and then I make an insert in that same script to the table called Prize Schedules.

The problem is that when executing that script it does not generate records in the aforementioned table.

Use python2.7 and Mysql

Here is the code:

import persistencia 
import random
query ="SELECT id_profe FROM profes"
datos = persistencia.Consulta(query)
print datos
idProfes = []
for dato in datos:  
idProfes.append( int(dato[0]) )

Dia =['Lunes, Martes, Miercoles, Jueves, Viernes']
for i in range (1000):
    HoraIni = random.randint (8,17)
    HoraFin = random.randint (8,17)

while HoraFin < HoraIni:
    HoraFin = random.randint (8, 17)
HoraIni = HoraIni
HoraFin = HoraFin
print HoraIni, HoraFin


diaProfe = random.choice(Dia)

idProfe = random.choice(idProfes)

sql = "INSERT INTO HorariosProfe (id_Profe, Hora_ini, Hora_fin, Dia) values ('"+str(idProfe)+"', '"+str(HoraIni)+"', '"+str(HoraFin)+"', '"+str(diaProfe)+"')"
persistencia.Inserta(sql)
    
asked by Shadow 23.04.2018 в 19:18
source

0 answers