-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
101 lines (82 loc) · 2.46 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from users import admin, user
from users.account import login, register
import pymysql.cursors
def create_connection():
"""
Creates a connection to the database
:return: The connection object
"""
DB_HOST = input("Enter MySQL hostname: ")
DB_USER = input("Enter MySQL user: ")
DB_PASSWORD = input("Enter MySQL password: ")
DB_NAME = input("Enter MySQL database: ")
connection = pymysql.connect(host=DB_HOST,
user=DB_USER,
password=DB_PASSWORD,
db=DB_NAME,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
return connection
def quit_program(cursor, connection):
"""
Quits the program
:param cursor: cursor object
:param connection: connection object
:return: None
"""
# Close the cursor
cursor.close()
# Close the connection
connection.close()
print("Exiting...")
print("Goodbye!")
exit()
def start_screen(cursor):
"""
Displays the start screen
:param cursor: The cursor object
:return: The current user
"""
while True:
print("Welcome to NBA Stats!")
print("Select an option: ")
print("1. Login")
print("2. Register")
print("3. Exit")
option = input("Enter option #: ")
match option:
case "1":
return login(cursor)
case "2":
return register(cursor)
case "3":
return
case _:
print("\nInvalid option\n")
def main():
"""
Main function
:return: None
"""
try:
# Connect to the database
connection = create_connection()
# connection autocommit enabled
connection.autocommit(True)
# Create a cursor object
cursor = connection.cursor()
# Start the program
current_user = start_screen(cursor)
if current_user is not None:
match current_user['admin']:
case 1:
admin.menu(cursor)
case 0:
user.menu(cursor)
case _:
print("Error: Invalid admin value! Account error contact admin!")
quit_program(cursor, connection)
except pymysql.Error as e:
print("Error %d: %s" % (e.args[0], e.args[1]))
if __name__ == "__main__":
main()