-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.py
85 lines (76 loc) · 2.17 KB
/
controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3
def conectar():
"""Funcion que conecta la base de datos
y retorna el conector
@return con"""
con = sqlite3.connect('movies.db')
con.row_factory = sqlite3.Row
return con
def obtener_movies():
"""Funcion que retorna la informacion de la tabla movies
@return productos"""
con = conectar()
c = con.cursor()
query = "SELECT * FROM movies"
resultado = c.execute(query)
movies = resultado.fetchall()
con.close()
return movies
def infoFila(codigo):
"""Funcion que retorna la informacion de una fila
@return valores"""
con = conectar()
c = con.cursor()
query = "SELECT * FROM movies WHERE id=?"
resultado = c.execute(query, [codigo])
infoFila = resultado.fetchall()
con.close()
for row in infoFila:
valores = [row[1], row[2], row[3], row[4], row[5], row[6], row[7],row[8]]
return valores
def infoFila2(codigo):
"""Funcion que retorna la informacion de una fila
@return valores"""
con = conectar()
c = con.cursor()
query = "SELECT * FROM movies WHERE id=?"
resultado = c.execute(query, [codigo])
infoFila = resultado.fetchall()
con.close()
for row in infoFila:
valores = [row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7],row[8]]
return valores
def subir(iD,valores):
"""Funcion que edita un valor en la
base de datos y retorna una variable
booleana
@param codigo,valores
@return exito"""
exito = False
con = conectar()
c = con.cursor()
# iD = valores[0]
ti = valores[0]
po = valores[1]
year = valores[2]
dirc = valores[3]
coun = valores[4]
star = valores[5]
des = valores[6]
ran = iD
total = (ti, po, year, dirc, coun, star, des, ran,iD)
query = '''UPDATE movies
SET title=?,poster=?,release_year=?, director=?,country=?, stars=?, description=?, ranking=?
WHERE iD=? '''
try:
c.execute(query, total)
con.commit()
exito = True
except sqlite3.Error as e:
exito = False
print "Error:",e.arg[0]
con.close()
if __name__ == '__main__':
print "hola"