-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
95 lines (78 loc) · 3.24 KB
/
Client.py
File metadata and controls
95 lines (78 loc) · 3.24 KB
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
86
87
88
89
90
91
92
93
94
95
import Pyro4
import os
print("CONNECTING TO FRONTEND")
#finding the frontend
with Pyro4.locateNS() as ns:
uri = ns.lookup("FRONTEND")
frontend = Pyro4.Proxy(uri)
#instructions for using the UI
def information():
print("\nWelcome to the MovieLens Database, Here are the things you can do:")
print("To find out information about a movie, type 'find'")
print("To view your rating for a movie type, 'view'")
print("To see the average rating for a movie, type 'average'")
print("To add or update your rating for a movie, type 'rate'")
print("To delete your rating for a movie, type 'delete'")
print("[TESTING ONLY] To change a server's status between online and offline, type 'change'")
print("To quit, type 'quit'\n")
#userID obtained before any actions can be made
userID = ""
while userID == "":
userID = input("Please enter your userID: ")
if not userID.isdigit():
userID = ""
print("\nINVALID\n")
#gets a user instruction, this whole section handles user inputs and makes sure everything they send to the front end is a valid input
userInstruction = ""
while userInstruction == "": #will keep asking for instructions unless the user wants to quit
information()
queryActions = ["find","view","average"]#all query actions
updateActions = ["rate","delete"]#all update actions
userInstruction = input("\nWhat would you like to do? ")
action = userInstruction.lower()
if action in queryActions:#queries
movie = input("\nWhat is the name of the movie? ")
while movie == "":
print("\nDon't leave it blank!")
movie = input("\nWhat is the name of the movie? ")
os.system('cls')
print("\n"+frontend.userQuery(action,movie,userID))
elif action in updateActions:#updates
rating = 0
movie = input("\nWhat is the name of the movie? ")
while movie == "":
print("\nDon't leave it blank!")
movie = input("\nWhat is the name of the movie? ")
if action == "rate":
invalid = True
while invalid == True:
invalid = False
rating = input("\nWhat rating would you like to give it(0-5)? ")
try:
float(rating)
except ValueError:
invalid = True
print("\nINVALID")
if not invalid:
if not 0 <= float(rating) <= 5:
invalid = True
print("\nINVALID")
os.system('cls')
print(frontend.userUpdate(action,movie,userID,rating))
elif action == "change":#changing server state
while True:
server = input("Which server's state would you like to change?(1-3) ")
if server.isdigit():
if 1 <= int(server) <= 3:
break
else:
print("\nINVALID")
else:
print("\nINVALID")
os.system('cls')
print(frontend.changeStatus(int(server)-1))
if action == "quit":#quitting
os.system('cls')
print("\nOkay thanks for coming!")
else:
userInstruction = ""