-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain1.py
293 lines (226 loc) · 7.67 KB
/
main1.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import mysql.connector as sql
import pandas as pd
pas= input("Enter your mysql password: ")
try:
mydb=sql.connect(host='localhost',user='root',password=pas)
cur = mydb.cursor()
except:
print("Incorrect password")
exit()
try:
mydb.autocommit = True
cur.execute("create database show_db")
cur.execute("use show_db")
cur.execute("create table Login_id(User_name varchar(20) primary key ,password varchar(20))")
cur.execute("create table show_table (Name varchar(40),Genre varchar(20),Status varchar(20), Score int(2), TV_or_Movie varchar(10))")
except:
cur.execute("use show_db")
def reg_log():
print('''
======================== WELCOME TO SHOW MANAGER =======================
1. Register
2. Login
3. Exit
========================================================================
''')
n=int(input('Enter your choice: '))
if n== 1:
name=input('Enter a Unique Username: ')
passwd=int(input('Enter a Password: '))
sql_insert="INSERT INTO Login_id (user_name,password) values ('{}','{}')".format(name,passwd)
cur.execute(sql_insert)
mydb.commit()
print("User created succesfully")
input("Press Enter to continue...")
reg_log()
elif n==2 :
name=input('Enter your Username: ')
passwd=int(input('Enter your Password: '))
cur.execute("select * from Login_id where user_name= '{}' and password='{}'".format(name,passwd))
exist = cur.fetchall()
if exist == []:
print('Invalid username or password')
else:
print("Logged in!")
menu()
elif n==3:
print("THANK YOU!!")
exit()
else:
print('''
Incorrect input
Try again!
''')
input("Press Enter to continue...")
reg_log()
def display_all():
cur.execute("select * from show_table")
results=cur.fetchall()
mydb.commit()
df = pd.DataFrame(results, columns=cur.column_names)
print(df)
input("Press Enter to continue...")
menu()
def display_tv():
cur.execute("select * from show_table where TV_or_Movie = 'TV Show' ")
results=cur.fetchall()
mydb.commit()
df = pd.DataFrame(results, columns=cur.column_names)
print(df)
input("Press Enter to continue...")
menu()
def display_mov():
cur.execute("select * from show_table where TV_or_Movie = 'Movie' ")
results=cur.fetchall()
mydb.commit()
df = pd.DataFrame(results, columns=cur.column_names)
print(df)
input("Press Enter to continue...")
menu()
def add_show():
name=input ("Enter the name of the show: ")
genre=input( "Enter the genre of the show: ")
status=input( "Enter the status of the show: ")
score=int(input("Enter the score of the show out of 10:"))
tvormov= int(input('''
It is a
1. TV show
2. Movie
->Enter the choice:
'''))
if tvormov ==1:
tv_mov = "TV Show"
elif tvormov ==2:
tv_mov = "Movie"
else:
print('''
Incorrect input
Try again!
''')
sql_insert="insert into show_table values('{}','{}','{}','{}','{}')".format(name,genre,status,score,tv_mov)
cur.execute(sql_insert)
mydb.commit()
print("Show added successfully!")
input("Press Enter to continue...")
menu()
def modify_menu():
print(
'''============================= SHOW MANAGER =============================
1. Change name of the show
2. Change genre of the show
3. Change status of the show
4. Change score of the show
5. Change type of the show
6. Back
7. Exit
========================================================================
''')
choice=int(input("->Enter the choice: "))
if choice==1:
old_name= input("Enter the name of the show you want to change: ")
new_name= input(f"Enter the new name of {old_name}: ")
cur.execute("update show_table set name = '{}' where name = '{}' ".format(new_name,old_name))
mydb.commit()
elif choice==2:
old_name= input("Enter the name of the show whose genre you want to change: ")
new_genre= input(f"Enter the new genre of {old_name}: ")
cur.execute("update show_table set genre = '{}' where name = '{}' ".format(new_genre,old_name))
mydb.commit()
elif choice==3:
old_name= input("Enter the name of the show whose status you want to change: ")
new_status= input(f"Enter the new status of {old_name}: ")
cur.execute("update show_table set status = '{}' where name = '{}' ".format(new_status,old_name))
mydb.commit()
elif choice==4:
old_name= input("Enter the name of the show whose score you want to change: ")
new_score= input(f"Enter the new score of {old_name}: ")
cur.execute("update show_table set score = '{}' where name = '{}' ".format(new_score,old_name))
mydb.commit()
elif choice==5:
old_name= input("Enter the name of the show whose type you want to change: ")
tvormov= int(input('''
It is a
1. TV show
2. Movie
->Enter the choice:
'''))
if tvormov ==1:
cur.execute("update show_table set TV_or_Movie = 'TV Show' where name = '{}' ".format(old_name))
mydb.commit()
elif tvormov ==2:
cur.execute("update show_table set TV_or_Movie = 'Movie' where name = '{}' ".format(old_name))
mydb.commit()
else:
print('''
Incorrect input
Try again!
''')
input("Press Enter to continue...")
menu()
elif choice==6:
menu()
elif choice==7:
print("THANK YOU!")
exit()
else:
print('''
Incorrect input
Try again!
''')
input("Press Enter to continue...")
menu()
def delete_show():
delete_row_name= input("Enter the name of the show you want to delete: ")
cur.execute("delete from show_table where name = '{}' ".format(delete_row_name))
mydb.commit()
input("Press Enter to continue...")
menu()
def user_list():
cur.execute("select user_name from Login_id order by user_name asc")
user=cur.fetchall()
df = pd.DataFrame(user, columns=cur.column_names)
print(df)
input("Press Enter to continue...")
menu()
def menu():
print(
'''============================= SHOW MANAGER =============================
1. Display all the shows
2. Display TV shows
3. Display Movies
4. Add a show
5. Modify a show
6. Delete a show
7. Users list
8. Exit
========================================================================
''')
choice=int(input("->Enter the choice: "))
if choice==1:
display_all()
elif choice==2:
display_tv()
elif choice==3:
display_mov()
elif choice==4:
add_show()
elif choice==5:
modify_menu()
elif choice==6:
delete_show()
elif choice==7:
user_list()
elif choice==8:
print("THANK YOU!!")
exit()
else:
print('''
Incorrect input
Try again!
''')
input("Press Enter to continue...")
menu()
def main():
reg_log()
if __name__ == "__main__":
main()