forked from kravisankaran/fatEar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit1.py
executable file
·1949 lines (1637 loc) · 106 KB
/
init1.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
# Import Flask Library
import hashlib
import time
from datetime import datetime
from functools import wraps
import pymysql.cursors
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
###Initialize the app from Flask
app = Flask(__name__)
app.secret_key = "secret key"
# Configure MySQL
conn = pymysql.connect(host='localhost',
port=8889,
user='root',
password='root',
db='FatEar',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
def login_required(f):
@wraps(f)
def dec(*args, **kwargs):
if not "username" in session:
return redirect(url_for("login"))
return f(*args, **kwargs)
return dec
def checkUserExist(username):
with conn.cursor() as cursor:
query = "SELECT * FROM user WHERE username = '%s'" % (username)
cursor.execute(query)
result = cursor.fetchall()
return result
def checkPlaylistExists(username, playlistName):
with conn.cursor() as cursor:
query = "SELECT * FROM playlist WHERE username = '%s' and playlistName = '%s'" % (username, playlistName)
cursor.execute(query)
result = cursor.fetchall()
print("result : %s", result)
return result
def getSongIDFromSong(song):
with conn.cursor() as cursor:
query = "SELECT songID FROM song WHERE title like '%s'" % (song)
cursor.execute(query)
result = cursor.fetchall()
return result
def getAlbumIDFromAlbum(album):
with conn.cursor() as cursor:
query = "SELECT albumID FROM album WHERE albumName like '%s'" % (album)
cursor.execute(query)
result = cursor.fetchall()
return result
def getArtistIDFromArtist(fname, lname):
with conn.cursor() as cursor:
if fname == None and lname != None:
query = "SELECT artistID FROM artist WHERE lname like '%s'" % (lname)
elif fname != None and lname == None:
query = "SELECT artistID FROM artist WHERE fname like '%s'" % (fname)
else:
query = "SELECT artistID FROM artist WHERE fname like '%s' and lname like '%s'" % (fname, lname)
cursor.execute(query)
result = cursor.fetchall()
return result
def getSongIDFromAlbum(albumID):
with conn.cursor() as cursor:
query = "SELECT songID FROM songInAlbum WHERE albumID = '%s'" % (albumID)
cursor.execute(query)
result = cursor.fetchall()
return result
def getSongIDFromArtist(artistID):
with conn.cursor() as cursor:
query = "SELECT songID FROM artistPerformsSong WHERE artistID = '%s'" % (artistID)
cursor.execute(query)
result = cursor.fetchall()
return result
def getSongIDFromGenre(genre):
with conn.cursor() as cursor:
query = "SELECT songID FROM songGenre WHERE genre like '%s'" % (genre)
cursor.execute(query)
result = cursor.fetchall()
return result
def getSongIDFromRateSong(songID):
with conn.cursor() as cursor:
print(songID)
query = "SELECT songID FROM rateSong WHERE songID in ({})".format(str(songID)[1:-1])
cursor.execute(query)
result = cursor.fetchall()
# print (result)
return result
def getSongs():
with conn.cursor() as cursor:
query = "SELECT songID FROM song"
cursor.execute(query)
result = cursor.fetchall()
print("songID", result)
return result
# Define a route to hello function
@app.route('/')
def hello():
return render_template('index.html')
# Define route for login
@app.route('/login')
def login():
return render_template('login.html')
# Define route for register
@app.route('/register')
def register():
return render_template('register.html')
# Authenticates the login
@app.route('/loginAuth', methods=['GET', 'POST'])
def loginAuth():
username = request.form['username']
plaintextPasword = request.form['password']
hashedPassword = hashlib.sha256(plaintextPasword.encode("utf-8")).hexdigest()
cursor = conn.cursor()
query = 'SELECT * FROM user WHERE username = %s and pwd = %s'
cursor.execute(query, (username, hashedPassword))
data = cursor.fetchone()
error = None
if (data):
session['username'] = username
conn.commit()
cursor.close()
return redirect(url_for('home'))
else:
# returns an error message to the html page
error = 'Invalid login or username'
return render_template('login.html', error=error)
# Authenticates the register
@app.route('/registerAuth', methods=['GET', 'POST'])
def registerAuth():
username = request.form['username']
plaintextPasword = request.form['password']
hashedPassword = hashlib.sha256(plaintextPasword.encode("utf-8")).hexdigest()
fname = request.form['First Name']
lname = request.form['Last Name']
nickname = request.form['nickname']
cursor = conn.cursor()
query = 'SELECT * FROM user WHERE username = %s'
cursor.execute(query, (username))
data = cursor.fetchone()
error = None
if (data):
# If the previous query returns data, then user exists
error = "This user already exists"
return render_template('register.html', error=error)
else:
ins = 'INSERT INTO user VALUES(%s, %s, %s, %s, %s, %s)'
cursor.execute(ins, (username, hashedPassword, fname, lname, time.strftime('%Y-%m-%d %H:%M:%S'), nickname))
conn.commit()
cursor.close()
return render_template('login.html')
@app.route('/logout')
def logout():
lastlogin = time.strftime('%Y-%m-%d %H:%M:%S')
cursor = conn.cursor()
username = session['username']
update = 'UPDATE user SET lastlogin = %s WHERE username = %s'
cursor.execute(update, (lastlogin, username))
conn.commit()
cursor.close()
session.pop('username')
return redirect('/')
@app.route('/home')
@login_required
def home():
user = session['username']
cursor = conn.cursor()
cursor.close()
return render_template('home.html', username=user)
def _checkEmptyParams(x):
if x == "":
return 0
else:
return 1
def getUpdatedSearchQuery(x, song, fname, lname, album, ratingVal, genre):
if x['s'] and x['a'] and x['f'] and x['l'] and x['r'] and x['g']:
print('song, album, fname, lname, rating, genre picked')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and alb.albumName like %s and rat.stars >= %s and gen.genre like %s", (
song, fname, lname, album, ratingVal, genre)
elif x['s'] and x['a'] and x['f'] and x['l'] and x['g']:
print('song, album, fname, lname, genre picked')
print('checking rating: ', checkIfRatingExistsWithSong(song))
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithAlbum(album) and checkIfRatingExistsWithArtist(
fname, lname) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and alb.albumName like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, fname, lname, album, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and alb.albumName like %s and gen.genre like %s", (
song, fname, lname, album, genre)
elif x['s'] and x['a'] and x['f'] and x['r'] and x['g']:
print('song, album, fname, rating, genre picked')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and rat.stars >= %s and alb.albumName like %s and gen.genre like %s", (
song, fname, ratingVal, album, genre)
elif x['s'] and x['a'] and x['l'] and x['r'] and x['g']:
print('song, album, lname, rating, genre picked')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and rat.stars >= %s and alb.albumName like %s and gen.genre like %s", (
song, lname, ratingVal, album, genre)
elif x['f'] and x['a'] and x['l'] and x['r'] and x['g']:
print('fname, album, lname, rating, genre picked')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and rat.stars >= %s and alb.albumName like %s and gen.genre like %s", (
fname, lname, ratingVal, album, genre)
elif x['f'] and x['a'] and x['l'] and x['r'] and x['g']:
print('fname, song, lname, rating, genre picked')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and rat.stars >= %s and title like %s and gen.genre like %s", (
fname, lname, ratingVal, song, genre)
elif x['s'] and x['a'] and x['f'] and x['l'] and x['r']:
print('song, album, fname, lname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and alb.albumName like %s and rat.stars >= %s", (
song, fname, lname, album, ratingVal)
elif x['s'] and x['f'] and x['l'] and x['a']:
print('song, fname, lastname, album present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(fname,
lname) and checkIfRatingExistsWithAlbum(
album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre ", (
song, fname, lname, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and alb.albumName like %s ", (
song, fname, lname, album)
elif x['s'] and x['f'] and x['l'] and x['g']:
print('song, fname, lastname, genre present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(fname,
lname) and checkIfRatingExistsWithGenre(
genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre ", (
song, fname, lname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and gen.genre like %s", (
song, fname, lname, genre)
elif x['s'] and x['f'] and x['l'] and x['r']:
print('song, fname, lname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s and rat.stars >= %s", (
song, fname, lname, ratingVal)
elif x['s'] and x['f'] and x['a'] and x['r']:
print('song, fname, album, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and alb.albumName like %s and rat.stars >= %s", (
song, fname, album, ratingVal)
elif x['s'] and x['f'] and x['a'] and x['g']:
print('song, fname, album, genre present')
if (checkIfRatingExistsWithGenre(genre) and checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(
fname, None)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and alb.albumName like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, fname, album, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and alb.albumName like %s and gen.genre like %s", (
song, fname, album, genre)
elif x['s'] and x['f'] and x['r'] and x['g']:
print('song, fname, rating, genre present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and rat.stars >= %s and gen.genre like %s", (
song, fname, ratingVal, genre)
elif x['s'] and x['l'] and x['a'] and x['r']:
print('song, lname, album, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and alb.albumName like %s and rat.stars >= %s", (
song, lname, album, ratingVal)
elif x['s'] and x['l'] and x['a'] and x['g']:
print('song, lname, album, genre present')
if (checkIfRatingExistsWithGenre(genre) and checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(
None, lname)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and alb.albumName like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, lname, album, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.lname like %s and alb.albumName like %s and gen.genre like %s", (
song, lname, album, genre)
elif x['s'] and x['l'] and x['r'] and x['g']:
print('song, lname, rating, genre present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and rat.stars >= %s and gen.genre like %s", (
song, lname, ratingVal, genre)
elif x['f'] and x['l'] and x['a'] and x['r']:
print('fname, lname, album, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and alb.albumName like %s and rat.stars >= %s", (
fname, lname, album, ratingVal)
elif x['f'] and x['l'] and x['a'] and x['g']:
print('fname, lname, album, genre present')
if (checkIfRatingExistsWithArtist(fname, lname) and checkIfRatingExistsWithAlbum(
album) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and alb.albumName like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
fname, lname, album, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and alb.albumName like %s and gen.genre like %s", (
fname, lname, album, genre)
elif x['f'] and x['l'] and x['r'] and x['g']:
print('fname, lname, rating, genre present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and rat.stars >= %s and gen.genre like %s ", (
fname, lname, ratingVal, genre)
elif x['f'] and x['a'] and x['r'] and x['g']:
print('fname, album, rating, genre present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and alb.albumName like %s and rat.stars >= %s and gen.genre like %s ", (
fname, album, ratingVal, genre)
elif x['l'] and x['a'] and x['r'] and x['g']:
print('fname, album, rating, genre present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.lname like %s and alb.albumName like %s and rat.stars >= %s and gen.genre like %s ", (
lname, album, ratingVal, genre)
elif x['s'] and x['a'] and x['r'] and x['g']:
print('song, album, rating, genre present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join rateSong rat natural join songGenre gen natural join artist a where title like %s and alb.albumName like %s and rat.stars >= %s and gen.genre like %s ", (
song, album, ratingVal, genre)
elif x['s'] and x['f'] and x['a']:
print('song, fname, album present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(fname,
None) and checkIfRatingExistsWithAlbum(
album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, fname, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and alb.albumName like %s", (
song, fname, album)
elif x['s'] and x['f'] and x['g']:
print('song, fname, genre present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(fname,
None) and checkIfRatingExistsWithGenre(
genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, fname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and gen.genre like %s", (
song, fname, genre)
elif x['s'] and x['f'] and x['r']:
print('song, fname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and rat.stars >= %s", (
song, fname, ratingVal)
elif x['s'] and x['f'] and x['l']:
print('song, artist fname, artist lname are present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(fname, lname)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, fname, lname)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s and a.lname like %s", (
song, fname, lname)
elif x['s'] and x['l'] and x['a']:
print('song, lname, album present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(None,
lname) and checkIfRatingExistsWithAlbum(
album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, lname, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.lname like %s and alb.albumName like %s", (
song, lname, album)
elif x['s'] and x['l'] and x['r']:
print('song, lname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and rat.stars >= %s", (
song, lname, ratingVal)
elif x['s'] and x['l'] and x['g']:
print('song, lname, genre present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(None,
lname) and checkIfRatingExistsWithGenre(
genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, lname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.lname like %s and gen.genre like %s", (
song, lname, genre)
elif x['f'] and x['l'] and x['a']:
print('fname, lname, album present')
if (checkIfRatingExistsWithArtist(fname, lname) and checkIfRatingExistsWithAlbum(album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
fname, lname, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and alb.albumName like %s", (
fname, lname, album)
elif x['f'] and x['l'] and x['g']:
print('fname, lname, genre present')
if (checkIfRatingExistsWithArtist(fname, lname) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
fname, lname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and gen.genre like %s", (
fname, lname, genre)
elif x['f'] and x['l'] and x['r']:
print('fname, lname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s and rat.stars >= %s", (
fname, lname, ratingVal)
elif x['a'] and x['l'] and x['r']:
print('album, lname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and a.lname like %s and rat.stars >= %s", (
album, lname, ratingVal)
elif x['a'] and x['l'] and x['g']:
print('album, lname, genre present')
if (checkIfRatingExistsWithAlbum(album) and checkIfRatingExistsWithArtist(None,
lname) and checkIfRatingExistsWithGenre(
genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and a.lname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
album, lname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where alb.albumName like %s and a.lname like %s and gen.genre like %s", (
album, lname, genre)
elif x['a'] and x['f'] and x['r']:
print('album, fname, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and a.fname like %s and rat.stars >= %s", (
album, fname, ratingVal)
elif x['a'] and x['f'] and x['g']:
print('album, fname, genre present')
if (checkIfRatingExistsWithAlbum(album) and checkIfRatingExistsWithArtist(fname,
None) and checkIfRatingExistsWithGenre(
genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and a.fname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
album, fname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where alb.albumName like %s and a.fname like %s and gen.genre like %s", (
album, fname, genre)
elif x['a'] and x['s'] and x['r']:
print('album, song, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and title like %s and rat.stars >= %s", (
album, song, ratingVal)
elif x['a'] and x['s'] and x['g']:
print('album, song, genre present')
if (checkIfRatingExistsWithAlbum(album) and checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithGenre(
genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and title like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
album, song, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where alb.albumName like %s and title like %s and gen.genre like %s", (
album, song, genre)
elif x['a'] and x['g'] and x['r']:
print('album, genre, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and gen.genre like %s and rat.stars >= %s", (
album, genre, ratingVal)
elif x['l'] and x['g'] and x['r']:
print('lname, genre, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.lname like %s and gen.genre like %s and rat.stars >= %s", (
lname, genre, ratingVal)
elif x['f'] and x['g'] and x['r']:
print('fname, genre, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and gen.genre like %s and rat.stars >= %s", (
fname, genre, ratingVal)
elif x['s'] and x['g'] and x['r']:
print('song, genre, rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and gen.genre like %s and rat.stars >= %s", (
song, genre, ratingVal)
elif x['s'] and x['f']:
print('song and artist fname present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(fname, None)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.fname like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, fname)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.fname like %s", (
song, fname)
elif x['s'] and x['l']:
print('song and artist lname present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithArtist(None, lname)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and a.lname like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, lname)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and a.lname like %s", (
song, lname)
elif x['f'] and x['l']:
print('artist fname and lname present')
if (checkIfRatingExistsWithArtist(fname, lname)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
fname, lname)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s and a.lname like %s", (
fname, lname)
elif x['f'] and x['a']:
print('artist fname and album name present')
if (checkIfRatingExistsWithArtist(fname, None) and checkIfRatingExistsWithAlbum(album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
fname, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s and alb.albumName like %s ", (
fname, album)
elif x['l'] and x['a']:
print('artist lname and album name present')
if (checkIfRatingExistsWithArtist(None, lname) and checkIfRatingExistsWithAlbum(album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.lname like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
lname, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.lname like %s and alb.albumName like %s", (
lname, album)
elif x['s'] and x['a']:
print('song and album present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithAlbum(album)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, album)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and alb.albumName like %s", (
song, album)
elif x['s'] and x['r']:
print('song and rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and rat.stars >= %s", (
song, ratingVal)
elif x['a'] and x['r']:
print('album and rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and rat.stars >= %s", (
album, ratingVal)
elif x['f'] and x['r']:
print('fname and rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and rat.stars >= %s", (
fname, ratingVal)
elif x['l'] and x['r']:
print('lname and rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.lname like %s and rat.stars >= %s", (
lname, ratingVal)
elif x['g'] and x['r']:
print('genre and rating present')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where gen.genre like %s and rat.stars >= %s", (
genre, ratingVal)
elif x['s'] and x['g']:
print('song and genre present')
if (checkIfRatingExistsWithSong(song) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
song, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where title like %s and gen.genre like %s", (
song, genre)
elif x['f'] and x['g']:
print('fname and genre present')
if (checkIfRatingExistsWithArtist(fname, None) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
fname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s and gen.genre like %s", (
fname, genre)
elif x['l'] and x['g']:
print('lname and genre present')
if (checkIfRatingExistsWithArtist(None, lname) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.lname like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
lname, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.lname like %s and gen.genre like %s", (
lname, genre)
elif x['a'] and x['g']:
print('album and genre present')
if (checkIfRatingExistsWithAlbum(album) and checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s and gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
album, genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where alb.albumName like %s and gen.genre like %s", (
album, genre)
elif x['f']:
print('only firstname')
print('checking rating: ', checkIfRatingExistsWithArtist(fname, None))
if (checkIfRatingExistsWithArtist(fname, None)):
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre, avg(rat.stars) as stars from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.fname like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre ", (
fname)
else:
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.fname like %s ", (
fname)
elif x['l']:
print('only lastname')
print('checking rating: ', checkIfRatingExistsWithArtist(None, lname))
if (checkIfRatingExistsWithArtist(None, lname)):
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre, avg(rat.stars) as stars from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where a.lname like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre ", (
lname)
else:
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where a.lname like %s ", (
lname)
elif x['s']:
print('only song')
print('checking rating: ', checkIfRatingExistsWithSong(song))
if (checkIfRatingExistsWithSong(song)):
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre, avg(rat.stars) as stars from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where title like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre ", (
song)
else:
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join songGenre gen natural join artist a where title like %s", (
song)
elif x['a']:
print('only album')
print('check rating:', checkIfRatingExistsWithAlbum(album))
if (checkIfRatingExistsWithAlbum(album)):
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre, avg(rat.stars) as stars from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where alb.albumName like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre ", (
album)
else:
return "select distinct s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb natural join songGenre gen natural join artist a where alb.albumName like %s", (
album)
elif x['r']:
print('only rating')
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, rat.stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where rat.stars >= %s", (
ratingVal)
elif x['g']:
print('only genre')
print('check rating:', checkIfRatingExistsWithGenre(genre))
if (checkIfRatingExistsWithGenre(genre)):
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, avg(rat.stars) as stars, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join rateSong rat natural join songGenre gen natural join artist a where gen.genre like %s group by s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre", (
genre)
else:
return "select s.title, a.fname, a.lname, s.releaseDate, alb.albumName, s.songURL, gen.genre from song s natural join artistPerformsSong asp natural join songInAlbum sap natural join album alb NATURAL join songGenre gen natural join artist a where gen.genre like %s", (
genre)
else:
print('nothing was picked')
def checkIfRatingExistsWithSong(song):
s = getSongIDFromSong(song)
print(s)
if s == None or len(s) == 0:
return 0
songID = [d['songID'] for d in s]
if (len(getSongIDFromRateSong(songID)) <= 0):
print(getSongIDFromRateSong(songID))
return 0
else:
set1 = songID
print("set1: ", set1)
set2 = getSongIDFromRateSong(songID)
l2 = [d['songID'] for d in set2]
print("set2: ", set2)
diff = set(set1) ^ set(l2)
if (len(diff) != 0):
print("Songs without rating", diff)
return 0
else:
print("All songs have a rating")
return 1
def checkIfRatingExistsWithAlbum(album):
a = getAlbumIDFromAlbum(album)
print(a)
if a == None or len(a) == 0:
return 0
albumID = a[0]['albumID']
print(albumID)
s = getSongIDFromAlbum(albumID)
songID = [d['songID'] for d in s]
print('songID:', songID)
if (len(getSongIDFromRateSong(songID)) <= 0):
print('No song from the album has ratings')
print(getSongIDFromRateSong(songID))
return 0
else:
set1 = songID
print("set1: ", set1)
set2 = getSongIDFromRateSong(songID)
l2 = [d['songID'] for d in set2]
print("set2: ", set2)
diff = set(set1) ^ set(l2)
if (len(diff) != 0):
print("Songs without rating", diff)
return 0
else:
print("All songs have a rating")
return 1
def checkIfRatingExistsWithArtist(fname, lname):
a = getArtistIDFromArtist(fname, lname)
print(a)
if a == None or len(a) == 0:
return 0
artistID = a[0]['artistID']
print(artistID)
s = getSongIDFromArtist(artistID)
songID = [d['songID'] for d in s]
print(songID)
if (len(getSongIDFromRateSong(songID)) <= 0):
print('No song by this artist has ratings')
print(getSongIDFromRateSong(songID))
return 0
else:
set1 = songID
print("set1: ", set1)
set2 = getSongIDFromRateSong(songID)
l2 = [d['songID'] for d in set2]
print("set2: ", set2)
diff = set(set1) ^ set(l2)
if (len(diff) != 0):
print("Songs by this artist without rating", diff)
return 0
else:
print("All songs by this artist have a rating")
return 1
def checkIfRatingExistsWithGenre(genre):
s = getSongIDFromGenre(genre)
if s == None or len(s) == 0:
return 0
songID = [d['songID'] for d in s]
print(songID)
if (len(getSongIDFromRateSong(songID)) <= 0):
print('No song in this genre has ratings')
print(getSongIDFromRateSong(songID))
return 0
else:
set1 = songID
print("set1: ", set1)
set2 = getSongIDFromRateSong(songID)
l2 = [d['songID'] for d in set2]
print("set2: ", set2)
diff = set(set1) ^ set(l2)
if (len(diff) != 0):
print("Songs in this genre that dont have a rating", diff)
return 0
else:
print("All songs in this genre have a rating")
return 1
@app.route('/search', methods=['GET', 'POST'])
def search():
if request.method == "POST":
print("in post method")
song = request.form['song']
artistFName = request.form['artistFName']
artistLName = request.form['artistLName']
album = request.form['album']
rating = request.form['rating']
genre = request.form['genre']
print(song)
print(artistFName)
print(artistLName)
print(album)
print(rating)
print(genre)
cursor = conn.cursor()
# song, artistF, artistLast, album
searchParams = [song, artistFName, artistLName, album, rating, genre]
keys = ["s", "f", "l", "a", "r", "g"]
status = list(map(_checkEmptyParams, searchParams))
parameterMap = {keys[i]: status[i] for i in range(len(keys))}
print(parameterMap)
song2 = "%" + song + "%"
artistFName2 = "%" + artistFName + "%"
artistLName2 = "%" + artistLName + "%"
album = "%" + album + "%"
genre = "%" + genre + "%"
# if rating is not None:
# ratingVal = int(rating)
query = getUpdatedSearchQuery(parameterMap, song2, artistFName2, artistLName2, album, rating, genre)
print(query)
if (query == None or len(query) <= 0):
message = 'No search params were entered, please refresh and try again!'
return render_template('search.html', error=message)
cursor.execute(query[0], query[1])
conn.commit()
data = cursor.fetchall()
if (len(data) <= 0):
message = 'No valid search results, please refresh and try again!'
return render_template('search.html', error=message)
return render_template('search.html', data=data)
return render_template('search.html')
def checkLength(field):
l = len(field)
if l <= 0 or l > 50:
return 0
return 1
@app.route('/playlist', methods=['GET', 'POST'])
def addPlaylist():
if request.method == "GET":
cursor = conn.cursor()
cursor.execute("select title from song")
songs = cursor.fetchall()
print(songs)
return render_template('playlist.html', songs=songs)
if request.method == "POST":
print("in post method")
playlistName = request.form['playlist']
userName = session['username']
description = request.form['description']
creationDate = str(datetime.now())
song = request.form.getlist('song-choice')
print(playlistName)
print(userName)
print(datetime)
print(song)
cursor = conn.cursor()
cursor.execute("select title from song")
songs = cursor.fetchall()
if (len(playlistName) <= 0 or playlistName is None):
print("PlaylistName empty")
message = 'Playlist name is required. Please refresh page and try again'
return render_template('playlist.html', error=message, songs=songs)
if (checkLength(playlistName) != 1):
print("PlaylistName exceeds length requirements")
message = 'Playlist name does not meet requirements should be between 1 and 50 chars. Please refresh page and try again'
return render_template('playlist.html', error=message, songs=songs)
if (checkPlaylistExists(userName, playlistName)):
message = 'You have already created a playlist with this name. Please refresh page and try again'
return render_template('playlist.html', error=message, songs=songs)
# song, artistF, artistLast, album
print("Creating new entry in Playlist Table")
cursor.execute(
"INSERT INTO playlist (username, playlistName, description, creationDate) VALUES(%s, %s, %s, %s)",
(userName, playlistName, description, creationDate))
if song != None:
if len(song) == 0:
message = 'You have chosen any song yet. Please refresh and try again'
return render_template('playlist.html', error=message, songs=songs)
print('box checked')
for item in song:
print("Calling method")
print(getSongIDFromSong(item))
s = getSongIDFromSong(item)
songID = s[0]['songID']
cursor.execute("INSERT INTO songsInPlaylist (username, playlistName, songID) VALUES(%s, %s, %s)",
(userName, playlistName, songID))
conn.commit()
cursor.execute(
"select title, playlistName, count(playlistName) as total from (select title, playlistName, username, sp.songID from song s join songsInPlaylist sp ON s.songID = sp.songID where username = %s and playlistName = %s) gsp group by playlistName, title order by playlistName",
(userName, playlistName))
data = cursor.fetchall()
print(data)
cursor.execute(
"select title, playlistName, count(playlistName) as total from (select title, playlistName, username, sp.songID from song s join songsInPlaylist sp ON s.songID = sp.songID where username = %s) gsp group by playlistName,title order by playlistName",
(userName))
alldata = cursor.fetchall()
print(alldata)
cursor.execute(
"select playlistName, count(playlistName) as total from (select title, playlistName, username, sp.songID from song s join songsInPlaylist sp ON s.songID = sp.songID where username = %s) gsp group by playlistName order by playlistName",
(userName))
countData = cursor.fetchall()
print(countData)
cursor.execute("select title from song")
songs = cursor.fetchall()
return render_template('playlist.html', data=data, songs=songs, count=countData, alldata=alldata)
return render_template('playlist.html', data=data, songs=songs, count=countData, alldata=alldata)
@app.route('/showplaylist', methods=['GET', 'POST'])
def showplaylist():
cursor = conn.cursor()
userName = session['username']
cursor.execute(
"select title, playlistName, count(playlistName) as total from (select title, playlistName, username, sp.songID from song s join songsInPlaylist sp ON s.songID = sp.songID where username = %s) gsp group by playlistName,title order by playlistName",
(userName))
alldata = cursor.fetchall()
print(alldata)
cursor.execute(
"select playlistName, count(playlistName) as total from (select title, playlistName, username, sp.songID from song s join songsInPlaylist sp ON s.songID = sp.songID where username = %s) gsp group by playlistName order by count(playlistName)",
(userName))
countData = cursor.fetchall()
print(countData)
return render_template('showplaylist.html', count=countData, alldata=alldata)
# friend
@login_required
def fetchFriendRequests():
cursor = conn.cursor()
query = "SELECT user2 FROM friend WHERE user1 = '%s' AND acceptStatus = 'pending'" % session["username"]
cursor.execute(query)
return cursor.fetchall()
@login_required
def fetchFriends():
cursor = conn.cursor()
user = session["username"]
query = "SELECT user1 as myFriend FROM friend WHERE user2=%s AND acceptStatus = 'accepted' UNION SELECT user2 as myFriend FROM friend WHERE user1=%s AND acceptStatus = 'accepted'"
cursor.execute(query, (user, user))
return cursor.fetchall()
@app.route("/friend", methods=["GET"])
@login_required
def friend():
request_data = fetchFriendRequests()
allf_data = fetchFriends()
return render_template("friend.html", friendRequests=request_data, allFriends=allf_data)
@app.route("/friendUser", methods=["POST", "GET"])
@login_required
def friendUser():
request_data = fetchFriendRequests()
allf_data = fetchFriends()
message = ' '
if request.form:
requestData = request.form
username_friended = requestData["username_friended"]
username_requester = session["username"]
if checkUserExist(username_friended):
if username_friended == username_requester:
message = "You cannot friend yourself!"
return render_template("friend.html", message=message, friendRequests=request_data,
allFriends=allf_data)
try:
cursor1 = conn.cursor()
statusQuery = "SELECT acceptStatus FROM friend WHERE (user1 = %s AND user2 = %s) OR (user2 = %s AND user1 = %s)"