Update database.py
This commit is contained in:
+70
-2
@@ -23,7 +23,8 @@ def log_in(email, password):
|
|||||||
|
|
||||||
if results:
|
if results:
|
||||||
for i in results:
|
for i in results:
|
||||||
print("Welcome " + i[1])
|
print("Welcome " + i[1]+"your balance is")
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
print("Email and password not recognised")
|
print("Email and password not recognised")
|
||||||
@@ -55,7 +56,15 @@ def view_movieinfo(filme):
|
|||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
for x in movies:
|
for x in movies:
|
||||||
print(x)
|
print(x)
|
||||||
results = c.fetchall()
|
|
||||||
|
if movies:
|
||||||
|
for i in movies:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("\n---movie name not correct---\n")
|
||||||
|
return(0)
|
||||||
|
|
||||||
|
return(x[1])
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
@@ -86,7 +95,66 @@ def compra_filme(custo,saldo,email):
|
|||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
saldofinal= saldo-custo
|
saldofinal= saldo-custo
|
||||||
c.execute("UPDATE users SET balance=(%s) WHERE email='"+email+"'",(saldofinal,))
|
c.execute("UPDATE users SET balance=(%s) WHERE email='"+email+"'",(saldofinal,))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def create_rent(custo,email,moviename):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=postgres")
|
||||||
|
c = conn.cursor()
|
||||||
|
timeavaible=c.execute("SELECT * FROM movies WHERE name ='"+moviename+"'")
|
||||||
|
results = c.fetchall()
|
||||||
|
for x in results:
|
||||||
|
break
|
||||||
|
|
||||||
|
userid=c.execute("SELECT * FROM users WHERE email ='"+email+"'")
|
||||||
|
results2 = c.fetchall()
|
||||||
|
for y in results2:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
type=x[9]
|
||||||
|
c.execute("INSERT INTO rent(clientid,date,price,dateend,usermail,timeavaible,type,movieid) VALUES ( %s, CURRENT_TIMESTAMP , %s, CURRENT_TIMESTAMP + %s * INTERVAL '1 month','"+email+"',%s,'"+type+"',%s)",(y[4],custo,x[8],x[8],x[0])) #falta tempo aos filmes
|
||||||
|
|
||||||
|
c.execute("SELECT date + timeavaible * INTERVAL '1 month' FROM rent;")
|
||||||
|
results3 = c.fetchall()
|
||||||
|
for z in results3:
|
||||||
|
break
|
||||||
|
|
||||||
|
# c.execute("INSERT INTO rent(dateend) VALUES('z')")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def view_rent(email):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=postgres")
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT * FROM rent WHERE usermail = '" + email + "'")
|
||||||
|
results = c.fetchall()
|
||||||
|
for x in results:
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def view_avaible_movies(email):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=postgres")
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT * FROM rent WHERE dateend >= CURRENT_TIMESTAMP AND usermail='"+email+"'")
|
||||||
|
results = c.fetchall()
|
||||||
|
id = 0
|
||||||
|
for x in results:
|
||||||
|
#print(x[8])
|
||||||
|
id=x[8]
|
||||||
|
c.execute("SELECT * FROM movies WHERE itemid = " + str(x[8]))
|
||||||
|
movies = c.fetchall()
|
||||||
|
for y in movies:
|
||||||
|
print(y[1])
|
||||||
|
#results2 = c.fetchall()
|
||||||
|
#print("movies and tv shows available:")
|
||||||
|
#for y in results2:
|
||||||
|
# print(y[2])
|
||||||
|
print("movies not available any more:")
|
||||||
|
c.execute("SELECT * FROM rent WHERE dateend <= CURRENT_TIMESTAMP AND usermail='" + email + "'")
|
||||||
|
results = c.fetchall()
|
||||||
|
|||||||
Reference in New Issue
Block a user