Ver Mensaje Individual
  #5 (permalink)  
Antiguo 07/08/2009, 15:43
Kinopio
 
Fecha de Ingreso: diciembre-2007
Ubicación: Frente al ordenador...
Mensajes: 139
Antigüedad: 16 años, 5 meses
Puntos: 1
Respuesta: python y mysql

import MySQLdb
import sys
import datetime
db=MySQLdb.connect(host='localhost',user='root',pa sswd='pass',db='pruebas')
C=db.cursor()

#--------------------------------------------------------------------------
def menu(N):
opc = int(N)

if opc == 1:
num = raw_input('Cuantos quieres mostrar?: ')
mostrar_tabla(int(num))
elif opc == 2:
actualizar()
else:
sys.exit()

#--------------------------------------------------------------------------
def mostrar_tabla(N):
keri = 'SELECT * FROM tabla ORDER BY Fecha DESC;'
C.execute(keri)
res = C.fetchall()
num = int(N)
x = c_nc(num)
i=0

while i < num -1 :
print res[i][0],'|',res[i][1],res[i][2],res[i][3],res[i][4],res[i][5],'|',centro_no(res[i][1]),centro_no(res[i][2]),centro_no(res[i][3]),centro_no(res[i][4]),centro_no(res[i][5]),'|',arriba_abajo(res[i][1]),'|',uno_dos(arriba_abajo(res[i][2]),arriba_abajo(res[i][3])),'*',uno_dos(arriba_abajo(res[i][4]),arriba_abajo(res[i][5])),'|',x[0][i],'|',x[1][i]
i = i + 1

#---------------------------------------------------------------------------
def actualizar():
#keri = 'SELECT * FROM tabla1;'
#C.execute(keri)
#res = C.fetchall()
n = []
i = 0

anio = ""
mes = ""
dia = ""
while not anio or not mes or not dia:
anio = int(raw_input('Introduce anio:'))
mes = int(raw_input('Introduce mes:'))
dia = int(raw_input('Introduce dia:'))


dait = datetime.date(anio,mes,dia)

num = raw_input('Introduce el numero:')
numero = list(num)
n = []

while not numero or len(numero) != 5:
num = raw_input('Introduce el numero:')
numero = list(num)

i=0
while i < len(numero):
n.append(int(numero[i]))
i += 1

#aquí cambie el query para probar la insercion...parece que la realiza pero no inserta realmente en la tabla, tampoco como el codigo que habias puesto...

otrokeri = "INSERT INTO tabla(Fecha, No1, No2, No3, No4, No5) VALUES('2009-08-06', '1', '2', '3', '4', '5');"
C.execute(otrokeri)

#---------------------------------------------------------------------------
def arriba_abajo(N):
num = int(N)

if num < 5:
return 'a'
else:
return 'A'
#---------------------------------------------------------------------------
def centro_no(N):
num = int(N)

if num == 2 or num == 7:
return 'C'
elif num == 0 or num == 1 or num == 5 or num == 6:
return 'v'
else:
return '^'

#---------------------------------------------------------------------------
def uno_dos(N1,N2):
n1=N1
n2=N2

if n1 == 'a' and n2 == 'a':
return '1'

elif n1 == 'a' and n2 == 'A':
return '2'

elif n1 == 'A' and n2 == 'a':
return '3'
else :
return '4'
#---------------------------------------------------------------------------
def c_nc(N):
keri = 'SELECT * FROM tabla1 ORDER BY Fecha DESC;'
C.execute(keri)
res = C.fetchall()
x = int(N)

NUM = []
NUM1= []
NUM2= []
LIS = []
LIS1= []
LIS2= []
i=j=0
i2=1

while i < x:
NUM.append (uno_dos(arriba_abajo(res[i][2]), arriba_abajo(res[i][3])))
NUM1.append (uno_dos(arriba_abajo(res[i][4]), arriba_abajo(res[i][5])))
i += 1

NUM2.append(NUM)
NUM2.append(NUM1)

while j < x and i2 < x:
LIS.append(checar_c_nc(NUM2[0][j], NUM2[0][i2]))
LIS1.append(checar_c_nc(NUM2[1][j], NUM2[1][i2]))
j += 1
i2 += 1

LIS2.append(LIS)
LIS2.append(LIS1)

return LIS2
#---------------------------------------------------------------------------
def checar_c_nc(N1,N2):
n1 = N1
n2 = N2

if n1 == "1" and n2 == "4" or n1 == "4" and n2 == "1":
return 'C'
elif n1== "2" and n2 == "3" or n1 == "3" and n2 == "2":
return 'C'
else:
return '-'
#----------------------------------------------------------------------------

mostrar_tabla(3)

print 'MENU:'
print '1-->Mostrar mas Datos'
print '2-->Actualizar Datos'
print '3-->Salir'
opcion = raw_input("Que deseas hacer?: ")

menu(opcion)

he ahi el codigo, espero me puedas ayudar...
__________________
----------------------------------------------------------
Algunas cosas simplemente son bellas...por que uno no puede tenerlas...