Add files via upload
This commit is contained in:
+145
-1
@@ -1,7 +1,6 @@
|
|||||||
import psycopg2
|
import psycopg2
|
||||||
global USERID
|
global USERID
|
||||||
|
|
||||||
|
|
||||||
# MENU
|
# MENU
|
||||||
def create_user(name, email, password):
|
def create_user(name, email, password):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
@@ -148,6 +147,88 @@ def message_client(msg, recieverid, senderid):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
# SEARCH ARTICLES
|
# SEARCH ARTICLES
|
||||||
|
def findby_name(name):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
|
c = conn.cursor()
|
||||||
|
y=0
|
||||||
|
c.execute("SELECT * FROM articles WHERE name like '%" + name + "%'")
|
||||||
|
movies = c.fetchall()
|
||||||
|
for x in movies:
|
||||||
|
y=y+1
|
||||||
|
print("\t"+str(y)+") "+x[1])
|
||||||
|
|
||||||
|
if movies:
|
||||||
|
for i in movies:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("\n---movie name not correct---\n")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return (0)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return(movies)
|
||||||
|
def findby_director(director):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
|
y = 0
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT * FROM articles WHERE director like '%" + director + "%'")
|
||||||
|
movies = c.fetchall()
|
||||||
|
for x in movies:
|
||||||
|
y = y + 1
|
||||||
|
print("\t" + str(y) + ") " + x[1])
|
||||||
|
|
||||||
|
if movies:
|
||||||
|
for i in movies:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("\n---movie director name not correct---\n")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return (movies)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
def findby_type(type):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
|
y = 0
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT * FROM articles WHERE type like '%" + type + "%'")
|
||||||
|
movies = c.fetchall()
|
||||||
|
for x in movies:
|
||||||
|
y = y + 1
|
||||||
|
print("\t" + str(y) + ") " + x[1])
|
||||||
|
|
||||||
|
if movies:
|
||||||
|
for i in movies:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("\n---movie type not correct---\n")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return (0)
|
||||||
|
return (movies)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
def findby_actor(actor):
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
|
j=0
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT * FROM actors WHERE name like('%"+actor+"%')")
|
||||||
|
actors = c.fetchall()
|
||||||
|
print("\r")
|
||||||
|
for x in actors:
|
||||||
|
actorid=x[0]
|
||||||
|
c.execute("SELECT * FROM articles_actors WHERE actors_actorid = '"+str(actorid)+"' ")
|
||||||
|
articles_actors = c.fetchall()
|
||||||
|
for y in articles_actors:
|
||||||
|
j = j + 1
|
||||||
|
c.execute("SELECT * FROM articles WHERE itemid = '"+str(y[0])+"' ")
|
||||||
|
articles = c.fetchall()
|
||||||
|
print(str("\t"+str(j)+") "+articles[0][1]))
|
||||||
|
|
||||||
|
return (articles)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
def list_all():
|
def list_all():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
@@ -455,6 +536,7 @@ def remove_article(n_id):
|
|||||||
if result:
|
if result:
|
||||||
print("\n\tCan't remove article because there are user(s) renting it")
|
print("\n\tCan't remove article because there are user(s) renting it")
|
||||||
else:
|
else:
|
||||||
|
c.execute("DELETE FROM articles_actors WHERE articles_itemid = '" + str(itemid) + "'")
|
||||||
c.execute("DELETE FROM articles WHERE itemid = '" + str(itemid) + "'")
|
c.execute("DELETE FROM articles WHERE itemid = '" + str(itemid) + "'")
|
||||||
print("\n\tArticle removed successfully")
|
print("\n\tArticle removed successfully")
|
||||||
|
|
||||||
@@ -470,3 +552,65 @@ def alter_balance(userid, balance):
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
def statistics():
|
||||||
|
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
||||||
|
total=0
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT articles_itemid FROM rents")
|
||||||
|
rents = c.fetchall()
|
||||||
|
for x in rents:
|
||||||
|
c.execute("SELECT * FROM articles WHERE itemid= '"+str(x[0])+"' ")
|
||||||
|
price=c.fetchall()
|
||||||
|
for y in price:
|
||||||
|
total=total+y[6]
|
||||||
|
print("\rTotal spent by all users: "+str(total))
|
||||||
|
|
||||||
|
contadorusers=0
|
||||||
|
c.execute("SELECT * FROM users")
|
||||||
|
users=c.fetchall()
|
||||||
|
for y in users:
|
||||||
|
contadorusers=contadorusers+1
|
||||||
|
|
||||||
|
print("\rTotal number of users: " + str(contadorusers-1))
|
||||||
|
|
||||||
|
contadorarticles = 0
|
||||||
|
c.execute("SELECT * FROM articles")
|
||||||
|
articles = c.fetchall()
|
||||||
|
for z in articles:
|
||||||
|
contadorarticles = contadorarticles + 1
|
||||||
|
print("\rTotal number of articles: " + str(contadorarticles))
|
||||||
|
|
||||||
|
contadorarticles = 0
|
||||||
|
total_movies=0
|
||||||
|
c.execute("SELECT * FROM articles where type = 'movie' ")
|
||||||
|
movies = c.fetchall()
|
||||||
|
for a in movies:
|
||||||
|
contadorarticles = contadorarticles + 1
|
||||||
|
total_movies=total_movies+a[6]
|
||||||
|
print("\rTotal number of movies: " + str(contadorarticles))
|
||||||
|
|
||||||
|
contadorarticles = 0
|
||||||
|
total_series=0
|
||||||
|
c.execute("SELECT * FROM articles where type = 'series' ")
|
||||||
|
series = c.fetchall()
|
||||||
|
for b in series:
|
||||||
|
contadorarticles = contadorarticles + 1
|
||||||
|
total_series=total_series+b[6]
|
||||||
|
print("\rTotal number of series: " + str(contadorarticles))
|
||||||
|
|
||||||
|
print("\rTotal spent in movies: "+str(total_movies))
|
||||||
|
print("\rTotal spent in series: "+str(total_series))
|
||||||
|
|
||||||
|
total2=0
|
||||||
|
c.execute("SELECT * FROM rents WHERE end_date > CURRENT_DATE ")
|
||||||
|
rents2 = c.fetchall()
|
||||||
|
for e in rents2:
|
||||||
|
c.execute("SELECT * FROM articles WHERE itemid= '"+str(e[3])+"' ")
|
||||||
|
price2=c.fetchall()
|
||||||
|
for d in price2:
|
||||||
|
total2=total2+d[6]
|
||||||
|
|
||||||
|
print("\rTotal spent on movies currently available: "+str(total2))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import database
|
import database
|
||||||
|
#para ser admin tem de conter @netflox.com
|
||||||
|
|
||||||
def menu():
|
def menu():
|
||||||
menu_interface = """
|
menu_interface = """
|
||||||
@@ -46,16 +46,88 @@ def client():
|
|||||||
2) Purchase
|
2) Purchase
|
||||||
0) Exit
|
0) Exit
|
||||||
Your Selection: """
|
Your Selection: """
|
||||||
|
search_interface = """
|
||||||
|
1) Title
|
||||||
|
2) Director
|
||||||
|
3) Type
|
||||||
|
4) Actors
|
||||||
|
Your Selection: """
|
||||||
client_interface = """
|
client_interface = """
|
||||||
1) List all articles
|
1) Search articles
|
||||||
2) Order by
|
2) List all articles
|
||||||
3) View my articles
|
3) Order by
|
||||||
4) My history
|
4) View my articles
|
||||||
5) Messages
|
5) My history
|
||||||
|
6) Messages
|
||||||
0) Exit
|
0) Exit
|
||||||
Your Selection: """
|
Your Selection: """
|
||||||
while (client_input := input(client_interface)) != '0':
|
while (client_input := input(client_interface)) != '0':
|
||||||
if client_input == '1':
|
if client_input == '1':
|
||||||
|
while (client_search := input(search_interface)) != '0':
|
||||||
|
if client_search == '1':
|
||||||
|
client_search_typo=input("\tInsert movie name: ")
|
||||||
|
article=database.findby_name(client_search_typo)
|
||||||
|
while (x := int(input("\tYour Selection: "))) != 0:
|
||||||
|
print("\n\t" + article[x - 1][1])
|
||||||
|
while (client_in := input(article_interface)) != '0':
|
||||||
|
if client_in == '1':
|
||||||
|
database.view_details(article[x - 1][0])
|
||||||
|
if client_in == '2':
|
||||||
|
if str(input("\n\tAre you sure (y/n): ")) == "y":
|
||||||
|
database.purchase(article[x - 1][0], USERID)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
|
||||||
|
if client_search == '2':
|
||||||
|
client_search_typo=input("\tInsert movie director: ")
|
||||||
|
article=database.findby_director(client_search_typo)
|
||||||
|
while (x := int(input("\tYour Selection: "))) != 0:
|
||||||
|
print("\n\t" + article[x - 1][1])
|
||||||
|
while (client_in := input(article_interface)) != '0':
|
||||||
|
if client_in == '1':
|
||||||
|
database.view_details(article[x - 1][0])
|
||||||
|
if client_in == '2':
|
||||||
|
if str(input("\n\tAre you sure (y/n): ")) == "y":
|
||||||
|
database.purchase(article[x - 1][0], USERID)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
|
||||||
|
if client_search == '3':
|
||||||
|
client_search_typo=input("\tInsert movie type: ")
|
||||||
|
article=database.findby_type(client_search_typo)
|
||||||
|
while (x := int(input("\tYour Selection: "))) != 0:
|
||||||
|
print("\n\t" + article[x - 1][1])
|
||||||
|
while (client_in := input(article_interface)) != '0':
|
||||||
|
if client_in == '1':
|
||||||
|
database.view_details(article[x - 1][0])
|
||||||
|
if client_in == '2':
|
||||||
|
if str(input("\n\tAre you sure (y/n): ")) == "y":
|
||||||
|
database.purchase(article[x - 1][0], USERID)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
if client_search == '4':
|
||||||
|
client_search_typo=input("\tInsert movie actor: ")
|
||||||
|
article=database.findby_actor(client_search_typo)
|
||||||
|
while (x := int(input("\tYour Selection: "))) != 0:
|
||||||
|
print("\n\t" + article[x - 1][1])
|
||||||
|
while (client_in := input(article_interface)) != '0':
|
||||||
|
if client_in == '1':
|
||||||
|
database.view_details(article[x - 1][0])
|
||||||
|
if client_in == '2':
|
||||||
|
if str(input("\n\tAre you sure (y/n): ")) == "y":
|
||||||
|
database.purchase(article[x - 1][0], USERID)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
|
||||||
|
if client_input == '2':
|
||||||
article = database.list_all()
|
article = database.list_all()
|
||||||
while (x := int(input("\tYour Selection: "))) != 0:
|
while (x := int(input("\tYour Selection: "))) != 0:
|
||||||
print("\n\t" + article[x - 1][1])
|
print("\n\t" + article[x - 1][1])
|
||||||
@@ -70,7 +142,7 @@ def client():
|
|||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
|
|
||||||
if client_input == '2':
|
if client_input == '3':
|
||||||
while (client_in := input(order_interface)) != '0':
|
while (client_in := input(order_interface)) != '0':
|
||||||
if client_in == '1':
|
if client_in == '1':
|
||||||
article = database.order_title()
|
article = database.order_title()
|
||||||
@@ -178,16 +250,16 @@ def client():
|
|||||||
break
|
break
|
||||||
break
|
break
|
||||||
|
|
||||||
if client_input == '3':
|
if client_input == '4':
|
||||||
article_id = database.my_articles(USERID)
|
article_id = database.my_articles(USERID)
|
||||||
if article_id != 0:
|
if article_id != 0:
|
||||||
database.time_left(article_id, USERID)
|
database.time_left(article_id, USERID)
|
||||||
|
|
||||||
if client_input == '4':
|
if client_input == '5':
|
||||||
if database.my_history(USERID) == 0:
|
if database.my_history(USERID) == 0:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if client_input == '5':
|
if client_input == '6':
|
||||||
message_interface = """
|
message_interface = """
|
||||||
1) View unread messages
|
1) View unread messages
|
||||||
2) View read messages
|
2) View read messages
|
||||||
@@ -214,6 +286,7 @@ def admin():
|
|||||||
4) Remove article
|
4) Remove article
|
||||||
5) Messages
|
5) Messages
|
||||||
6) Alter user balance
|
6) Alter user balance
|
||||||
|
7) Statistics
|
||||||
0) Exit
|
0) Exit
|
||||||
Your Selection: """
|
Your Selection: """
|
||||||
admin_article = """
|
admin_article = """
|
||||||
@@ -280,10 +353,13 @@ def admin():
|
|||||||
balance = input("\tNew balance: ")
|
balance = input("\tNew balance: ")
|
||||||
database.alter_balance(userid, balance)
|
database.alter_balance(userid, balance)
|
||||||
|
|
||||||
|
if admin_input == '7':
|
||||||
|
database.statistics()
|
||||||
|
|
||||||
|
|
||||||
if menu() != -1:
|
if menu() != -1:
|
||||||
USERID = database.USERID
|
USERID = database.USERID
|
||||||
client()
|
client()
|
||||||
else:
|
else:
|
||||||
USERID = database.USERID
|
USERID = database.USERID
|
||||||
admin()
|
admin()
|
||||||
Reference in New Issue
Block a user