From d3fe51212149a6342ab3169c92d2ffbcfae09fc7 Mon Sep 17 00:00:00 2001 From: agsNeto20 <37492761+agsNeto20@users.noreply.github.com> Date: Thu, 10 Dec 2020 20:01:01 +0000 Subject: [PATCH] Delete database_TOTAL --- database_TOTAL | 506 ------------------------------------------------- 1 file changed, 506 deletions(-) delete mode 100644 database_TOTAL diff --git a/database_TOTAL b/database_TOTAL deleted file mode 100644 index 256bba4..0000000 --- a/database_TOTAL +++ /dev/null @@ -1,506 +0,0 @@ -import psycopg2 - -global USERID - - -# MENU FUNCTIONS -def create_user(name, email, password): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - if email.find('@netflox.com') == -1: - c.execute( - "INSERT INTO users (nome, email, password, balance) VALUES ('" + name + "','" + email + "','" + password + "',20)") - else: - print("\n\tInsert a valid email address") - - conn.commit() - conn.close() - - -def log_in(email, password): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - if email.find('@netflox.com') == -1: - c.execute("SELECT * FROM users WHERE email = '" + email + "' AND password = '" + password + "'") - results = c.fetchall() - - global USERID - - conn.commit() - conn.close() - - if results: - for i in results: - print("\n\tWelcome " + i[1]) - USERID = i[0] - return 1 # client - else: - print("\n\tEmail and password not recognised\n") - return 0 - - elif email.find('@netflox.com') != -1: - c.execute("SELECT * FROM users WHERE email = '" + email + "' AND password = '" + password + "'") - results = c.fetchall() - - conn.commit() - conn.close() - - if results: - for i in results: - print("\n\tWelcome Admin " + i[1]) - USERID = i[0] - return -1 # admin - else: - print("\n\tEmail and password not recognised\n") - return 0 - - -# MESSAGES CLIENT -def show_unread_messages(userid): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - c.execute("SELECT * FROM messages WHERE users_userid = " + str(userid) + " AND bolread = FALSE") - messages = c.fetchall() - - y = 0 - print("\r") - for i in messages: - c.execute("SELECT * FROM users WHERE userid = " + str(i[4])) - sender = c.fetchall() - for x in sender: - y += 1 - print("\t" + str(y) + ") Message from " + x[1] + " date: " + str(i[5])) - - print("\t0) Exit") - - conn.commit() - conn.close() - - return messages - - -def show_read_messages(userid): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - c.execute("SELECT * FROM messages WHERE users_userid = " + str(userid) + " AND bolread = TRUE") - messages = c.fetchall() - - y = 0 - print("\n") - for i in messages: - c.execute("SELECT * FROM users WHERE userid = " + str(i[4])) - sender = c.fetchall() - for x in sender: - y += 1 - print("\t" + str(y) + ") Message from " + x[1] + " date: " + str(i[5])) - - print("\t0) Exit") - - conn.commit() - conn.close() - - return messages - - -def read_message(msgid): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - c.execute("UPDATE messages SET bolread = TRUE WHERE msgid='" + str(msgid) + "'") - - conn.commit() - conn.close() - - -# ADMIN -def add_article(name, actorid, director, imbdrating, genre, price,year,monthsavaible,type): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - # TODO multiple actor id - c.execute( - "INSERT INTO movies(name, actorid, director, year, imdbrating, genre, price,timeavaible,type )VALUES('" + name + "','" + actorid + "','" + director + "', '"+year+"','" + imbdrating + "','" + genre + "','" + price + "','"+monthsavaible+"','"+type+"')") - print("\n\t" + name + " was added to movies") - - conn.commit() - conn.close() - - -def change_price(n_id, newprice): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - itemid = n_id - if isinstance(n_id, str): - c.execute("SELECT itemid FROM movies WHERE name = '" + n_id + "'") - n_id = c.fetchall() - for i in n_id: - itemid = i[0] - - c.execute("SELECT price FROM movies WHERE itemid = '" + str(itemid) + "'") - result = c.fetchall() - oldprice = 0 - for i in result: - oldprice = i[0] - - c.execute("UPDATE movies SET price = '" + str(newprice) + "' WHERE itemid = '" + str(itemid) + "'") - c.execute( - "INSERT INTO pricehistory(oldprice, data, movies_itemid) VALUES('" + str(oldprice) + "', CURRENT_DATE,'" + str( - itemid) + "')") - - print("\n\tPrice updated successfully") - print("\tOld price saved to history") - - conn.commit() - conn.close() - - -def remove_article(n_id): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - itemid = n_id - if isinstance(n_id, str): - c.execute("SELECT itemid FROM movies WHERE name = '" + n_id + "'") - n_id = c.fetchall() - for i in n_id: - itemid = i[0] - - # TODO if client has movie dont remove - c.execute("DELETE FROM movies WHERE itemid = '" + str(itemid) + "'") - print("\n\tMovie removed successfully") - - conn.commit() - conn.close() - - -def message_all(msg, senderid): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - c.execute("SELECT userid FROM users") - results = c.fetchall() - - c.execute("SELECT Sum(pg_column_size(userid))/4 as total_size FROM users") - size = c.fetchall()[0][0] - - i = 0 - while i < size: - if results[i][0] != senderid: - c.execute( - "INSERT INTO messages (message, bolread, users_userid, senderid, data) VALUES ('" + msg + "', FALSE, '" + str( - results[i][0]) + "', '" + str(senderid) + "', CURRENT_DATE)") - i += 1 - - print("\n\tMessage sent to all") - - conn.commit() - conn.close() - - -def message_client(msg, recieverid, senderid): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - c.execute( - "INSERT INTO messages (message, bolread, users_userid, senderid, data) VALUES ('" + msg + "', FALSE, '" + - str(recieverid) + "', '" + str(senderid) + "', CURRENT_DATE)") - - print("\n\tMessage sent successfully") - - conn.commit() - conn.close() - - -def alter_balance(userid, balance): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - - c.execute("UPDATE users SET balance = '"+str(balance)+"' WHERE userid='" + str(userid) + "'") - - print("\n\tBalance updated successfully") - - conn.commit() - conn.close() - -def view_allmovies():#imprimeosfilmes - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies") - movies=c.fetchall() - for x in movies: - print(x[1]) - conn.commit() - conn.close() - -def view_movieinfo(filme): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies WHERE name = '" + filme + "'") - movies = c.fetchall() - for x in movies: - print(x) - - if movies: - for i in movies: - break - else: - print("\n---movie name not correct---\n") - return(0) - - return(x[1]) - conn.commit() - conn.close() - -def view_saldo(USERID): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM users WHERE userid = '" + str(USERID) + "'") - results = c.fetchall() - for x in results: - print(x[4]) - return(x[4]) - conn.commit() - conn.close() - -def view_custo(filme): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies WHERE name = '" + filme + "'") - results = c.fetchall() - for x in results: - print(x[6]) - return(x[6]) - conn.commit() - conn.close() - -def compra_filme(custo,saldo,USERID): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - saldofinal= saldo-custo - c.execute("UPDATE users SET balance=(%s) WHERE userid='"+str(USERID)+"'",(saldofinal,)) - conn.commit() - conn.close() - -def create_rent(custo,USERID,moviename): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - 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 userid ='"+str(USERID)+"'") - 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',%s,%s,'"+type+"',%s)",(y[0],custo,x[8],y[2],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(USERID): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM rent WHERE clientid = '" + str(USERID) + "'") - results = c.fetchall() - for x in results: - print(x) - - - conn.commit() - conn.close() - - -def view_avaible_movies(USERID): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM rent WHERE dateend >= CURRENT_TIMESTAMP AND clientid='"+str(USERID)+"'") - results = c.fetchall() - print("------------") - print("movies available:") - 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]) - - print("------------") - print("movies not available any more:") - c.execute("SELECT * FROM rent WHERE CURRENT_TIMESTAMP > dateend AND clientid='" + str(USERID) + "'") - results2 = c.fetchall() - id = 0 - for z in results2: - id2 = z[8] - c.execute("SELECT * FROM movies WHERE itemid = " + str(z[8])) - movies2 = c.fetchall() - for r in movies2: - print(r[1]) - print("------------") - - -def findby_name(name): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies WHERE name like '%" + name + "%'") - movies = c.fetchall() - for x in movies: - print(x) - - if movies: - for i in movies: - break - else: - print("\n---movie name not correct---\n") - return (0) - print("\n") - conn.commit() - conn.close() - -def findby_director(director): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies WHERE director like '%" + director + "%'") - movies = c.fetchall() - for x in movies: - print(x[3]+"----"+x[1]) - - - if movies: - for i in movies: - break - else: - print("\n---movie director name not correct---\n") - return (0) - print("\n") - conn.commit() - conn.close() - -def findby_type(type): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies WHERE type like '%" + type + "%'") - movies = c.fetchall() - for x in movies: - print(x[9]+"----"+x[1]) - - if movies: - for i in movies: - break - else: - print("\n---movie type not correct---\n") - return (0) - print("\n") - conn.commit() - conn.close() - -def findby_actor(actor): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM actors WHERE name like('%"+actor+"%')") - #c.execute("SELECT * FROM actors WHERE movieid['"+str(n)+"']=5") - actors = c.fetchall() - for x in actors: - break - id=x[2] - size=len(id) - for y in range(0,size): - c.execute("SELECT * FROM movies WHERE itemid=('"+str(id[y])+"')") - movies=c.fetchall() - for z in movies: - print(x[1],"----",z[1]) - conn.commit() - conn.close() - -def view_allmovies_ordertitle(): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies ORDER BY name;") - movies = c.fetchall() - for x in movies: - print(x[1]) - conn.commit() - conn.close() - -def view_allmovies_orderdirector(): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies ORDER BY director;") - movies = c.fetchall() - for x in movies: - print(x[3]+"---"+x[1]) - conn.commit() - conn.close() - -def view_allmovies_orderdate(): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies ORDER BY year;") - movies = c.fetchall() - for x in movies: - print(str(x[7])+"------"+x[1]) - conn.commit() - conn.close() - -def view_allmovies_orderimdb(): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM movies ORDER BY imdbrating;") - movies = c.fetchall() - for x in movies: - print(str(x[4])+"-----"+x[1]) - conn.commit() - conn.close() - -#def view_availablemovies_ordertitle(USERID): - - -def view_availablemovies_orderdirector(USERID): - conn = psycopg2.connect("host=localhost dbname=projeto user=postgres password=") - c = conn.cursor() - c.execute("SELECT * FROM rent WHERE dateend >= CURRENT_TIMESTAMP AND clientid='"+str(USERID)+"'") - results = c.fetchall() - print("------------") - print("movies available:") - id = 0 - movies=0 - for x in results: - id=x[8] #id's que queremos ir buscar - print(id) - c.execute("SELECT * FROM movies WHERE itemid = '"+str(id)+"' ORDER BY director") - movies += c.fetchall() - for y in movies: - print(y[3]+"---"+y[1]) - - print("------------") - print("movies not available any more:") - c.execute("SELECT * FROM rent WHERE CURRENT_TIMESTAMP > dateend AND clientid='" + str(USERID) + "'") - results2 = c.fetchall() - id = 0 - for z in results2: - id2 = z[8] - c.execute("SELECT * FROM movies WHERE itemid = "+ str(z[8]) ) - movies2 = c.fetchall() - for r in movies2: - print(r[1]) - print("------------") -#def view_availablemovies_orderdate(USERID): -#def view_availablemovies_orderimdb(USERID): -