-
Notifications
You must be signed in to change notification settings - Fork 0
/
film_stream.py
2400 lines (2180 loc) · 100 KB
/
film_stream.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# cd boss_code
# cd .\boss_code
#!/usr/bin/python
import mysql.connector
import streamlit as st
from datetime import datetime
from dbcreate import *
from movie import *
from rating import *
from actor import *
from genre import *
from feature import *
from studio import *
from price import *
from media import *
import pandas as pd
# Connect to database
# Create variables
user_input = ''
mydb = mysql.connector.connect(
host='localhost',
user='student',
password='student'
)
uname = st.text_input('Enter Username: ')
pwd = st.text_input('Enter Password: ', type='password')
if uname == 'student' and pwd == 'student':
st.success('Logged in as student')
st.write('\n')
print('Connected to Film database')
db_cursor = mydb.cursor()
# ask user via streamlit if they want to create/reset database
st.title('Welcome to the film Database')
st.write('Would you like to create/reset the database?')
placeholder = st.empty()
user_input = placeholder.text_input('Enter yes or no', key=1)
enter_button = st.button('Enter', key=8)
click_clear = st.button('Clear', key=3)
if user_input == 'yes' and enter_button:
create_db = create(db_cursor, mydb)
create_db.create_db()
if click_clear:
user_input = placeholder.text_input("", key=2)
if user_input == 'no' and enter_button:
st.write('Database not created/reset')
st.write('Please continue to use the database')
film = mysql.connector.connect(
host='localhost',
user='student',
password='student',
database='film'
)
mycursor = film.cursor()
print('Connected to MySQL film database')
st.write('Please select an option from the menus below')
if st.checkbox("Show PDF of the Film Database"):
test = mycursor.execute('''SELECT * FROM movie''')
newtest = mycursor.fetchall()
if not newtest:
st.write("There's no information in the database. Cannot generate PDF.")
else:
mycursor.execute('''
SELECT movie_title
, GROUP_CONCAT(DISTINCT studio_name) AS Studio
, GROUP_CONCAT(DISTINCT media_type) AS 'Media Type'
, movie_year
, GROUP_CONCAT(DISTINCT genre_name) AS Genre
, GROUP_CONCAT( DISTINCT CONCAT_WS(' ',actor_fname, actor_lname)) AS Actor
, GROUP_CONCAT( DISTINCT feature_name) AS Feature
, rating_level
, GROUP_CONCAT(DISTINCT CONCAT('$',price_value)) AS Price
FROM movie m
LEFT JOIN movie_studio ms ON m.movie_id = ms.movie_id
LEFT JOIN studio s ON ms.studio_id = s.studio_id
LEFT JOIN movie_media mm ON m.movie_id = mm.movie_id
LEFT JOIN media as me ON mm.media_id = me.media_id
LEFT JOIN price as p ON mm.price_id = p.price_id
LEFT JOIN movie_genre as mg ON m.movie_id = mg.movie_id
LEFT JOIN genre as g ON mg.genre_id = g.genre_id
LEFT JOIN cast as c ON m.movie_id = c.movie_id
LEFT JOIN actor as a ON c.actor_id = a.actor_id
LEFT JOIN movie_feature as mf ON m.movie_id = mf.movie_id
LEFT JOIN feature as f ON mf.feature_id = f.feature_id
LEFT JOIN rating as r ON m.rating_id = r.rating_id
GROUP BY movie_title, movie_year, rating_level, m.movie_id
ORDER BY m.movie_id;
''')
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Movie Title', 'Studio', 'Media Type', 'Movie Year', 'Genre', 'Actor', 'Feature', 'Rating', 'Price']
st.write(df)
user_input = st.selectbox("Rating Menu", [
"Choose an Option",
"View Ratings",
"Add Rating",
"Remove Rating"])
# View ratings
if user_input == "View Ratings":
test = mycursor.execute('''
SELECT rating_id
FROM rating
WHERE rating_id IS NOT NULL
''')
newtest = mycursor.fetchall()
if not newtest:
st.write("There are no ratings in the database.")
else:
mycursor.execute('''SELECT * FROM rating''')
# Print all rows formatted using panda dataframe
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Rating Id', 'Rating Level']
st.write(df)
st.write('\n')
# Add rating
if user_input == "Add Rating":
rating_level = st.selectbox("Add a Rating:", [
"Choose an Option",
"G",
"PG",
"PG-13"])
usr_button = st.button("Add Rating")
if usr_button:
add_rating = rating(mycursor, film)
add_rating.add_rating(rating_level)
st.write(mycursor.rowcount, 'record created.')
st.write('\n')
# Remove rating
elif user_input == "Remove Rating":
test = mycursor.execute('''
SELECT rating_id
FROM rating
WHERE rating_id IS NOT NULL
''')
newtest = mycursor.fetchall()
if not newtest:
st.write("There are no ratings in the database.")
else:
mycursor.execute('''SELECT * FROM rating''')
# Print all rows formatted using panda dataframe
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Rating Id', 'Rating Level']
st.write(df)
st.write('\n')
rating_id = st.text_input('Enter Rating Id: ')
st.write('\n')
usr_button = st.button("Remove Rating")
if usr_button:
remove_rating = rating(mycursor, film)
remove_rating.delete_rating(rating_id)
st.write(mycursor.rowcount, 'record deleted.')
st.write('\n')
# Movies
user_input = st.selectbox("Movie Menu", [
"Choose an Option",
"View Movies",
"Add Movie",
"Update Movie",
"Remove Movie"])
# Add movie
if user_input == 'Add Movie':
# st.write('Add Employee')
test = mycursor.execute('''
SELECT rating_id
FROM rating
WHERE rating_id IS NOT NULL
''')
newtest = mycursor.fetchall()
if not newtest:
st.write('No Ratings in Database. Cannot enter a movie.')
else:
movie_title = st.text_input('Enter Movie Title: ')
movie_year = st.number_input('Enter Release Year: ')
rating = mycursor.execute('''
SELECT rating_id, rating_level
FROM rating;
''')
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Rating ID','Rating Level']
st.write(df)
rating_id = st.text_input('Enter Rating ID: ')
st.write('\n')
usr_button = st.button('Add Movie')
# use dbcreate.py add_employee function
if usr_button:
add_mov = movie(mycursor, film)
add_mov.add_movie(movie_title, movie_year, rating_id)
st.write(mycursor.rowcount, 'record created.')
st.write('\n')
# Remove movie
elif user_input == 'Remove Movie':
# st.write('Remove Employee')
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Movies in Database')
else:
mycursor.execute('SELECT * FROM movie')
# Print all rows formatted using panda dataframe
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Movie Id', 'Movie Title', 'Movie Year', 'Rating Id']
st.write(df)
st.write('\n')
movie_id = st.text_input('Enter movie id: ')
st.write('\n')
usr_button = st.button('Remove Movie')
# use movie.py delete_movie function
if usr_button:
remove_mov = movie(mycursor, film)
remove_mov.delete_movie(movie_id)
st.write(mycursor.rowcount, 'record deleted.')
st.write('\n')
# Update movie details
elif user_input == 'Update Movie':
# st.write('Update Employee')
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No movies in Database.')
else:
mycursor.execute('''
SELECT movie_id
, movie_title
, movie_year
, rating_level
FROM movie m
LEFT JOIN rating r ON m.rating_id = r.rating_id
''')
# Print all rows formatted using panda dataframe
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Movie Id', 'Movie Title', 'Movie Year', 'Rating Id']
st.write(df)
st.write('\n')
movie_id = st.text_input('Enter Movie Id: ')
st.write('\n')
movie_update_button = st.checkbox('Update Selected Movie')
if movie_update_button:
mycursor.execute('''
SELECT movie_id
, rating_id
, movie_year
, movie_title
FROM movie
WHERE movie_id = %s
''', (movie_id,))
result = mycursor.fetchall()
if result is None:
st.write('Movie does not exist.')
else:
movie_id = result[0][0]
rating_id = result[0][1]
movie_year = result[0][2]
movie_title = result[0][3]
mycursor.execute('''
SELECT movie_id
, movie_title
, movie_year
, rating_id
FROM movie
WHERE movie_id = %s
''', (movie_id,))
result = mycursor.fetchall()
if result is None:
st.write('Movie does not exist.')
else:
result_df = pd.DataFrame(result)
result_df.columns = ['Movie Id', 'Movie Title', 'Movie Year', 'Rating Id']
st.write("Record to be updated: ")
st.write(result_df)
new_movie_title = st.text_input('Enter New Movie Title: ')
st.write('\n')
new_movie_year = st.text_input('Enter New Release Year (YYYY): ')
rating = mycursor.execute('''
SELECT rating_id, rating_level
FROM rating;
''')
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Rating ID','Rating Level']
st.write(df)
new_rating_id = st.text_input('Enter rating Id : ')
st.write('\n')
usr_button = st.button('Update Movie')
# use movie.py update_employee function
if usr_button:
if new_movie_title == '' and new_movie_year == '' and new_rating_id == '':
st.write('No changes made.')
if new_movie_year == '':
new_movie_year = movie_year
if new_movie_title == '':
new_movie_title = movie_title
if new_rating_id == '':
new_rating_id = rating_id
update_mov = movie(mycursor, film)
update_mov.update_movie(movie_id, new_movie_title, new_movie_year, new_rating_id)
st.write(mycursor.rowcount, 'record updated.')
st.write('\n')
# View movies
elif user_input == 'View Movies':
# st.write('View Movies')
st.write('\n')
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Movies in Database.')
else:
mycursor.execute('''SELECT * FROM movie''')
# Print all rows formatted using panda dataframe
df = pd.DataFrame(mycursor.fetchall())
df.columns = ['Movie Id', 'Movie Title', 'Movie Year', 'Rating Id']
st.write(df)
st.write('\n')
# Actors
actor_input = st.selectbox("Actor Menu", [
"Choose an Option",
"View Actors",
"Add Actor",
"Link Actor to Movie",
"Update Actor Link to Movie",
"Delete Actor Link to Movie",
"Update Actor",
"Delete Actor"])
# View actor
if actor_input == "View Actors":
# st.write('View Gear')
st.write('\n')
test = mycursor.execute('''
SELECT actor_id
FROM actor
WHERE actor_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Actors in Database.')
else:
# add functionality to filter by movie
if st.checkbox('Filter by Movie'):
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Movies in Database.')
else:
mycursor.execute('''
SELECT movie_id
, movie_title
FROM movie
''')
m_df = pd.DataFrame(mycursor.fetchall())
m_df.columns = ['Movie Id', 'Movie Title']
st.write(m_df)
movie_id = st.text_input('Enter Movie Id: ')
st.write('\n')
movie_filter_button = st.button('Filter')
if movie_filter_button:
mycursor.execute('''
SELECT movie_title
, GROUP_CONCAT( DISTINCT CONCAT_WS(' ',actor_fname, actor_lname)) AS Actor
FROM movie m
LEFT JOIN cast c ON m.movie_id = c.movie_id
LEFT JOIN actor a ON c.actor_id = a.actor_id
WHERE m.movie_id = %s
''', (movie_id,))
a_df = pd.DataFrame(mycursor.fetchall())
a_df.columns = ['Movie Title', 'Actors']
st.write(a_df)
st.write('\n')
else:
mycursor.execute('''
SELECT actor_fname
, actor_lname
FROM actor
''')
ac_df = pd.DataFrame(mycursor.fetchall())
ac_df.columns = ['Actor First Name', 'Actor Last Name']
st.write(ac_df)
st.write('\n')
# Add actor
elif actor_input == "Add Actor":
# st.write('Add Gear')
st.write('\n')
a_fname = st.text_input('Enter Actor First Name: ')
a_lname = st.text_input('Enter Actor Last Name: ')
if a_lname == '':
a_lname = ' '
actor_button = st.button('Add Actor')
# use gear.py add_gear function
if actor_button:
add_actor = actor(mycursor, film)
add_actor.add_actor(a_fname, a_lname)
st.write(mycursor.rowcount, 'record updated.')
st.write('\n')
# Link actor to movie
elif actor_input == "Link Actor to Movie":
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
test2 = mycursor.execute('''
SELECT actor_id
FROM actor
WHERE actor_id IS NOT NULL
''')
newtest2 = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest and not newtest2:
st.write('No Movies or Actors in the Database.')
elif not newtest:
st.write('No Movies in Database.')
elif not newtest2:
st.write('No Actors in Database.')
else:
mycursor.execute('''
SELECT movie_id
, movie_title
FROM movie
''')
a_df = pd.DataFrame(mycursor.fetchall())
a_df.columns = ['Movie Id', 'Movie Title']
st.write(a_df)
movie_id = st.text_input('Enter Movie Id: ')
st.write('\n')
mycursor.execute('''
SELECT actor_id
, actor_fname
, actor_lname
FROM actor
''')
a_df = pd.DataFrame(mycursor.fetchall())
a_df.columns = ['Actor Id', 'Actor First Name', 'Actor Last Name']
st.write(a_df)
actor_id = st.text_input('Enter Actor Id: ')
st.write('\n')
movie_actor_add = st.button('Add Actor to Movie')
if movie_actor_add:
add_movie_actor = actor(mycursor, film)
add_movie_actor.add_movie_actor(actor_id, movie_id)
st.write(mycursor.rowcount, 'record updated.')
st.write('\n')
# Update actor link to movie
elif actor_input == "Update Actor Link to Movie":
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
test2 = mycursor.execute('''
SELECT actor_id
FROM actor
WHERE actor_id IS NOT NULL
''')
newtest2 = mycursor.fetchall()
if not newtest and not newtest2:
st.write('No Movies or Actors in the Database.')
elif not newtest:
st.write('No Movies in Database.')
elif not newtest2:
st.write('No Actors in Database.')
else:
mycursor.execute('''
SELECT cast_id
, movie_title
, actor_fname
, actor_lname
FROM movie m
LEFT JOIN cast c ON m.movie_id = c.movie_id
LEFT JOIN actor a ON c.actor_id = a.actor_id
ORDER BY m.movie_id
''')
m_df = pd.DataFrame(mycursor.fetchall())
m_df.columns = ['Cast Id', 'Movie Title', 'Actor First Name', 'Actor Last Name']
st.write(m_df)
cast_id = st.text_input('Enter Cast Id: ')
st.write('\n')
movie_actor_button = st.checkbox('Update Actor Link to Movie')
if movie_actor_button:
mycursor.execute('''
SELECT movie_id
, actor_id
FROM cast
WHERE cast_id = %s
''', (cast_id,))
result = mycursor.fetchall()
if result is None:
st.write('Actor is not linked to movie.')
else:
movie_id = result[0][0]
actor_id = result[0][1]
mycursor.execute('''
SELECT m.movie_id
, movie_title
, a.actor_id
, actor_fname
, actor_lname
FROM movie m
LEFT JOIN cast c ON m.movie_id = c.movie_id
LEFT JOIN actor a ON c.actor_id = a.actor_id
WHERE cast_id = %s
ORDER BY m.movie_id
''', (cast_id,))
result = mycursor.fetchall()
if result is None:
st.write('Actor is not linked to movie.')
else:
result_df = pd.DataFrame(result)
result_df.columns = ['Movie Id', 'Movie Title', 'Actor Id', 'Actor First Name', 'Actor Last Name']
st.write("Record to be updated: ")
st.write(result_df)
mycursor.execute('''
SELECT movie_id
, movie_title
FROM movie
WHERE movie_id != %s
''', (movie_id,))
new_movie_df = pd.DataFrame(mycursor.fetchall())
new_movie_df.columns = ['Movie Id', 'Movie Title']
st.write('Available Movies: ')
st.write(new_movie_df)
new_movie_link_id = st.text_input('Enter Movie Id: ')
st.write('\n')
mycursor.execute('''
SELECT actor_id
, actor_fname
, actor_lname
FROM actor
WHERE actor_id != %s
''', (actor_id,))
new_actor_df = pd.DataFrame(mycursor.fetchall())
new_actor_df.columns = ['Actor Id', 'Actor First Name', 'Actor Last Name']
st.write('Available Actors: ')
st.write(new_actor_df)
new_actor_link_id = st.text_input('Enter Actor Id: ')
st.write('\n')
update_movie_actor = st.button('Link Actor to New Movie')
if update_movie_actor:
if new_movie_link_id == '' and new_actor_link_id == '':
st.write('No changes made.')
if new_movie_link_id == '':
new_movie_link_id = movie_id
if new_actor_link_id == '':
new_actor_link_id = actor_id
update_movie_actor = actor(mycursor, film)
update_movie_actor.update_movie_actor(actor_id, movie_id, new_movie_link_id, new_actor_link_id)
st.write(mycursor.rowcount, 'record updated.')
st.write('\n')
#Delete Actor Link to Movie
elif actor_input == "Delete Actor Link to Movie":
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
test2 = mycursor.execute('''
SELECT actor_id
FROM actor
WHERE actor_id IS NOT NULL
''')
newtest2 = mycursor.fetchall()
if not newtest and not newtest2:
st.write('No Movies or Actors in the Database.')
elif not newtest:
st.write('No Movies in Database.')
elif not newtest2:
st.write('No Actors in Database.')
else:
mycursor.execute('''
SELECT cast_id
, movie_title
, actor_fname
, actor_lname
FROM movie m
LEFT JOIN cast c ON m.movie_id = c.movie_id
LEFT JOIN actor a ON c.actor_id = a.actor_id
ORDER BY m.movie_id
''')
m_df = pd.DataFrame(mycursor.fetchall())
m_df.columns = ['Cast Id', 'Movie Title', 'Actor First Name', 'Actor Last Name']
st.write(m_df)
cast_id = st.text_input('Enter Cast Id: ')
st.write('\n')
movie_actor_button = st.checkbox('Delete Actor Link to Movie')
if movie_actor_button:
mycursor.execute('''
SELECT cast_id
, movie_title
, actor_fname
, actor_lname
FROM movie m
LEFT JOIN cast c ON m.movie_id = c.movie_id
LEFT JOIN actor a ON c.actor_id = a.actor_id
WHERE cast_id = %s
ORDER BY m.movie_id
''', (cast_id,))
result = mycursor.fetchall()
if result is None:
st.write('Actor is not linked to movie.')
else:
result_df = pd.DataFrame(result)
result_df.columns = ['Cast Id', 'Movie Title', 'Actor First Name', 'Actor Last Name']
st.write(result_df)
delete_movie_actor = st.button('Delete Actor Link to Movie')
if delete_movie_actor:
delete_movie_actor = actor(mycursor, film)
delete_movie_actor.delete_movie_actor(cast_id)
st.write(mycursor.rowcount, 'record deleted.')
st.write('\n')
#update actor
elif actor_input == "Update Actor":
st.write('\n')
test = mycursor.execute('''
SELECT actor_id
FROM actor
WHERE actor_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Actors in Database.')
else:
mycursor.execute('''
SELECT actor_id
, actor_fname
, actor_lname
FROM actor
''')
ua_df = pd.DataFrame(mycursor.fetchall())
ua_df.columns = ['Actor ID','Actor First Name','Actor Last Name']
st.write(ua_df)
actor_id = st.text_input('Enter Actor id: ')
st.write('\n')
a_fname = st.text_input('Enter Actor First Name: ')
st.write('\n')
a_lname = st.text_input('Enter Actor Last Name:')
up_actor_button = st.button('Update Actor')
if up_actor_button:
update_actor = actor(mycursor, film)
update_actor.update_actor(actor_id, a_fname, a_lname)
st.write(mycursor.rowcount, 'record updated')
st.write('\n')
# Delete actor
elif actor_input == 'Delete Actor':
test = mycursor.execute('''
SELECT actor_id
FROM actor
WHERE actor_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Actors in Database.')
else:
mycursor.execute(f'''
SELECT actor_id
, actor_fname
, actor_lname
FROM actor
''')
gr_df = pd.DataFrame(mycursor.fetchall())
gr_df.columns = ['Actor Id','Actor First Name', 'Actor Last Name']
st.write(gr_df)
actor_id = st.text_input('Enter Actor id: ')
st.write('\n')
del_actor_button = st.button('Delete Actor')
if del_actor_button:
delete_actor = actor(mycursor, film)
delete_actor.delete_actor(actor_id)
st.write(mycursor.rowcount, 'record deleted.')
st.write('\n')
# Genre
genre_input = st.selectbox("Genre Menu", [
"Choose an Option",
"View Genres",
"Add Genre",
"Link Genre to Movie",
"Update Genre Link to Movie",
"Delete Genre Link to Movie",
"Update Genre",
"Delete Genre"])
# View genres
if genre_input == "View Genres":
st.write('\n')
# If no repairs or if valueerror, print message
test = mycursor.execute('''
SELECT genre_id
FROM genre
WHERE genre_id IS NOT NULL
''')
newtest = mycursor.fetchall()
# print(newtest)
# if newtest is empty list, print message
if not newtest:
st.write('No Genres in Database.')
else:
# checkbox to filter by movie
if st.checkbox('Filter by Movie'):
mycursor.execute('''
SELECT movie_id
, movie_title
FROM movie
''')
m_df = pd.DataFrame(mycursor.fetchall())
m_df.columns = ['Movie Id', 'Movie Title']
st.write(m_df)
movie_id = st.text_input('Enter Movie Id: ')
st.write('\n')
movie_filter_button = st.button('Filter')
if movie_filter_button:
mycursor.execute('''
SELECT movie_title
, GROUP_CONCAT(DISTINCT genre_name) AS genre_name
FROM movie m
LEFT JOIN movie_genre mg ON m.movie_id = mg.movie_id
LEFT JOIN genre g ON mg.genre_id = g.genre_id
WHERE m.movie_id = %s
''', (movie_id,))
g_df = pd.DataFrame(mycursor.fetchall())
g_df.columns = ['Movie Title', 'Genre Name']
st.write(g_df)
st.write('\n')
else:
mycursor.execute('''
SELECT genre_id
, genre_name
FROM genre
''')
g_df = pd.DataFrame(mycursor.fetchall())
g_df.columns = ['Genre Id', 'Genre Name']
st.write(g_df)
st.write('\n')
# Add Genre
elif genre_input == "Add Genre":
st.write('\n')
genre_name = st.text_input('Enter Genre Name: ')
genre_button = st.button('Add Genre')
# use genre.py add_genre function
if genre_button:
add_genre = genre(mycursor, film)
add_genre.add_genre(genre_name)
st.write(mycursor.rowcount, 'record created.')
st.write('\n')
# Link Genre to Movie
elif genre_input == "Link Genre to Movie":
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
test2 = mycursor.execute('''
SELECT genre_id
FROM genre
WHERE genre_id IS NOT NULL
''')
newtest2 = mycursor.fetchall()
if not newtest and not newtest2:
st.write('No Movies or Genres in the Database.')
elif not newtest:
st.write('No Movies in Database.')
elif not newtest2:
st.write('No Genres in Database.')
else:
mycursor.execute('''
SELECT movie_id
, movie_title
FROM movie
''')
m_df = pd.DataFrame(mycursor.fetchall())
m_df.columns = ['Movie Id', 'Movie Title']
st.write(m_df)
movie_id = st.text_input('Enter Movie Id: ')
st.write('\n')
mycursor.execute('''
SELECT genre_id
, genre_name
FROM genre
''')
s_df = pd.DataFrame(mycursor.fetchall())
s_df.columns = ['Genre Id', 'Genre Name']
st.write(s_df)
genre_id = st.text_input('Enter Genre Id: ')
st.write('\n')
genre_movie_button = st.button('Add Genre to Movie')
if genre_movie_button:
add_genre_movie = genre(mycursor, film)
add_genre_movie.add_movie_genre(genre_id, movie_id)
st.write(mycursor.rowcount, 'record created.')
st.write('\n')
# Update Genre Link to Movie
elif genre_input == "Update Genre Link to Movie":
test = mycursor.execute('''
SELECT movie_id
FROM movie
WHERE movie_id IS NOT NULL
''')
newtest = mycursor.fetchall()
test2 = mycursor.execute('''
SELECT genre_id
FROM genre
WHERE genre_id IS NOT NULL
''')
newtest2 = mycursor.fetchall()
if not newtest and not newtest2:
st.write('No Movies or Genres in the Database.')
elif not newtest:
st.write('No Movies in Database.')
elif not newtest2:
st.write('No Genres in Database.')
else:
mycursor.execute('''
SELECT movie_genre_id
, movie_title
, genre_name
FROM movie m
LEFT JOIN movie_genre mg ON m.movie_id = mg.movie_id
LEFT JOIN genre g ON mg.genre_id = g.genre_id
ORDER BY m.movie_id
''')
m_df = pd.DataFrame(mycursor.fetchall())
m_df.columns = ['Movie Genre Id', 'Movie Title', 'Genre Name']
st.write(m_df)
movie_genre_id = st.text_input('Enter Movie Gerne Id: ')
st.write('\n')
genre_movie_button = st.checkbox('Update Genre Link to Movie')
if genre_movie_button:
mycursor.execute('''
SELECT movie_id
, genre_id
FROM movie_genre
WHERE movie_genre_id = %s
''', (movie_genre_id,))
result = mycursor.fetchall()
if result is None:
st.write('Genre is not linked to movie.')
else:
movie_id = result[0][0]
genre_id = result[0][1]
mycursor.execute('''
SELECT m.movie_id
, movie_title
, g.genre_id
, genre_name
FROM movie m
LEFT JOIN movie_genre mg ON m.movie_id = mg.movie_id
LEFT JOIN genre g ON mg.genre_id = g.genre_id
WHERE movie_genre_id = %s
ORDER BY m.movie_id
''', (movie_genre_id,))
result = mycursor.fetchall()
if result is None:
st.write('Genre is not linked to movie.')
else:
result_df = pd.DataFrame(result)
result_df.columns = ['Movie Id', 'Movie Title', 'Genre Id', 'Genre Name']
st.write("Record to be updated: ")
st.write(result_df)
mycursor.execute('''
SELECT genre_id
, genre_name
FROM genre
WHERE genre_id != %s
''', (genre_id,))
s_df = pd.DataFrame(mycursor.fetchall())
s_df.columns = ['Genre Id', 'Genre Name']
st.write("Available Genres: ")