import mysql.connector mydb = mysql.connector.connect(host=”localhost”, user=”root”, password=”1978@Tejas”) mycursor = mydb.cursor() try: mycursor.execute(“create database music;”) except: pass mycursor.execute(“use music;”) try: mycursor.execute(“create table SongData(S_id int(2),S_Name varchar(20),S_Artist varchar(20),S_Album varchar(20),User_id int(2));”) except: pass
try: mycursor.execute(“create table Userdata(Userid int(2),Username varchar(20),Playlistname varchar(20));”) except: pass
mycursor.execute(‘select * from Songdata;’) output=mycursor.fetchall()
if output == []:
mycursor.execute('insert into Songdata values(01,"Come & go","Juice WRLD","Legends never die",11);') mycursor.execute('insert into Songdata values(02,"Superman","Eminem","The Eminem Show",21);') mycursor.execute('insert into Songdata values(03,"Worldstar money","joji","In tounges",11);') mycursor.execute('insert into Songdata values(04,"Water fountain","Alec Benjamin","Narrated For you",21);') mycursor.execute('insert into Songdata values(05,"Iraaday","Rovalio","IRAADAY",31);') mycursor.execute('insert into Songdata values(06,"Without me","Eminem","The Eminem Show",21);') mycursor.execute('insert into Songdata values(07,"Sahiba","Aditya Rikhari","Sahiba",31);') mycursor.execute('insert into Songdata values(08,"Brilliant Mind","Blanco","ReBourne",11);')
mycursor.execute(‘select * from Userdata;’) output=mycursor.fetchall() if output == []: mycursor.execute(‘insert into Userdata values(11,”dhairya”,”dumcore”);’) mycursor.execute(‘insert into Userdata values(21,”kavish”,”doremon”);’) mycursor.execute(‘insert into Userdata values(31,”tejas”,”padhai kar le”);’)
def fetchsongdata(): mycursor.execute(‘select * from Songdata’) return mycursor.fetchall()
def checkUserId(id): mycursor.execute(‘select * from Userdata;’) userIds = mycursor.fetchall() for user in userIds: if user[0] == id: return True return False
def insertSong(id): songdata = fetchsongdata() print(“”) songname = input(“Song name: “) artist = input(“Artist: “) album = input(“Album: “) mycursor.execute(f’insert into Songdata values({len(songdata)+1},”{songname}”,”{artist}”,”{album}”,{id});’) print(“Song inserted”) print(“”) mydb.commit()
def createUser(): mycursor.execute(‘select * from userdata’) userdata = mycursor.fetchall()
name = input("UserName: ") playlistName = input("Playlist: ") userId = int(f"{len(userdata)+1}1") mycursor.execute(f'insert into userdata values({userId},"{name}","{playlistName}")') mydb.commit() return userId
def printSongs(): print(“———————————————————-“) print(“Sr no. Song Name, Artist, Playlist, User Id”) for l in mycursor.fetchall(): for data in l: print(f”{data}, “, end= “”) print(“”) print(“”) print(“———————————————————-“)
————- project ——–
print(“——–Spotipy Songs Database——“)
userId = int(input(“Enter User id: “)) try: mycursor.execute(f”select Username from Userdata where Userid = {userId}”) print(f”Welcome {mycursor.fetchall()[0][0]} to our Song Database”)
except: pass
while True: if userId == 00: print(“Admin Login!”) func = int(input(“1. Fetch alln2. Wiew Usersn3. quit”)) print(”) if func == 1: mycursor.execute(f”select * from Songdata”) printSongs() if func == 2: mycursor.execute(f”select * from Userdata”) print(mycursor.fetchall()) if func == 3: exit() else: print(“Invalid Output”)
elif checkUserId(userId): func = int(input("1. Insert n2. Fetchn3. Dropn4. Quitn")) print("n") if func == 1: insertSong(userId) elif func == 2: mycursor.execute(f"select * from Songdata where User_id = '{userId}' ") print("----------------------------------------------------------") print("Sr no. Song Name, Artist, Playlist, User Id") for l in mycursor.fetchall(): for data in l: print(f"{data}, ", end= "") print("") print("") print("----------------------------------------------------------") elif func == 3: selection = input("which ID to drop: ") mycursor.execute(f"DELETE FROM Songdata WHERE s_id = {int(selection)};") mydb.commit() elif func == 4: print("Thanks for using the song database!") exit() else: print("Invalid Output") else: func = input("Create new user(y/n)").lower() if func == "y": userId = createUser() print(f"Your New userId is: {userId}") elif func == "n": exit() else: print("invalid output")
submitted by /u/InteractionWeekly308
[link] [comments]
r/learnpython import mysql.connector mydb = mysql.connector.connect(host=”localhost”, user=”root”, password=”1978@Tejas”) mycursor = mydb.cursor() try: mycursor.execute(“create database music;”) except: pass mycursor.execute(“use music;”) try: mycursor.execute(“create table SongData(S_id int(2),S_Name varchar(20),S_Artist varchar(20),S_Album varchar(20),User_id int(2));”) except: pass try: mycursor.execute(“create table Userdata(Userid int(2),Username varchar(20),Playlistname varchar(20));”) except: pass mycursor.execute(‘select * from Songdata;’) output=mycursor.fetchall() if output == []: mycursor.execute(‘insert into Songdata values(01,”Come & go”,”Juice WRLD”,”Legends never die”,11);’) mycursor.execute(‘insert into Songdata values(02,”Superman”,”Eminem”,”The Eminem Show”,21);’) mycursor.execute(‘insert into Songdata values(03,”Worldstar money”,”joji”,”In tounges”,11);’) mycursor.execute(‘insert into Songdata values(04,”Water fountain”,”Alec Benjamin”,”Narrated For you”,21);’) mycursor.execute(‘insert into Songdata values(05,”Iraaday”,”Rovalio”,”IRAADAY”,31);’) mycursor.execute(‘insert into Songdata values(06,”Without me”,”Eminem”,”The Eminem Show”,21);’) mycursor.execute(‘insert into Songdata values(07,”Sahiba”,”Aditya Rikhari”,”Sahiba”,31);’) mycursor.execute(‘insert into Songdata values(08,”Brilliant Mind”,”Blanco”,”ReBourne”,11);’) mycursor.execute(‘select * from Userdata;’) output=mycursor.fetchall() if output == []: mycursor.execute(‘insert into Userdata values(11,”dhairya”,”dumcore”);’) mycursor.execute(‘insert into Userdata values(21,”kavish”,”doremon”);’) mycursor.execute(‘insert into Userdata values(31,”tejas”,”padhai kar le”);’) def fetchsongdata(): mycursor.execute(‘select * from Songdata’) return mycursor.fetchall() def checkUserId(id): mycursor.execute(‘select * from Userdata;’) userIds = mycursor.fetchall() for user in userIds: if user[0] == id: return True return False def insertSong(id): songdata = fetchsongdata() print(“”) songname = input(“Song name: “) artist = input(“Artist: “) album = input(“Album: “) mycursor.execute(f’insert into Songdata values({len(songdata)+1},”{songname}”,”{artist}”,”{album}”,{id});’) print(“Song inserted”) print(“”) mydb.commit() def createUser(): mycursor.execute(‘select * from userdata’) userdata = mycursor.fetchall() name = input(“UserName: “) playlistName = input(“Playlist: “) userId = int(f”{len(userdata)+1}1″) mycursor.execute(f’insert into userdata values({userId},”{name}”,”{playlistName}”)’) mydb.commit() return userId def printSongs(): print(“———————————————————-“) print(“Sr no. Song Name, Artist, Playlist, User Id”) for l in mycursor.fetchall(): for data in l: print(f”{data}, “, end= “”) print(“”) print(“”) print(“———————————————————-“) ————- project ——– print(“——–Spotipy Songs Database——“) userId = int(input(“Enter User id: “)) try: mycursor.execute(f”select Username from Userdata where Userid = {userId}”) print(f”Welcome {mycursor.fetchall()[0][0]} to our Song Database”) except: pass while True: if userId == 00: print(“Admin Login!”) func = int(input(“1. Fetch alln2. Wiew Usersn3. quit”)) print(”) if func == 1: mycursor.execute(f”select * from Songdata”) printSongs() if func == 2: mycursor.execute(f”select * from Userdata”) print(mycursor.fetchall()) if func == 3: exit() else: print(“Invalid Output”) elif checkUserId(userId): func = int(input(“1. Insert n2. Fetchn3. Dropn4. Quitn”)) print(“n”) if func == 1: insertSong(userId) elif func == 2: mycursor.execute(f”select * from Songdata where User_id = ‘{userId}’ “) print(“———————————————————-“) print(“Sr no. Song Name, Artist, Playlist, User Id”) for l in mycursor.fetchall(): for data in l: print(f”{data}, “, end= “”) print(“”) print(“”) print(“———————————————————-“) elif func == 3: selection = input(“which ID to drop: “) mycursor.execute(f”DELETE FROM Songdata WHERE s_id = {int(selection)};”) mydb.commit() elif func == 4: print(“Thanks for using the song database!”) exit() else: print(“Invalid Output”) else: func = input(“Create new user(y/n)”).lower() if func == “y”: userId = createUser() print(f”Your New userId is: {userId}”) elif func == “n”: exit() else: print(“invalid output”) submitted by /u/InteractionWeekly308 [link] [comments]
import mysql.connector mydb = mysql.connector.connect(host=”localhost”, user=”root”, password=”1978@Tejas”) mycursor = mydb.cursor() try: mycursor.execute(“create database music;”) except: pass mycursor.execute(“use music;”) try: mycursor.execute(“create table SongData(S_id int(2),S_Name varchar(20),S_Artist varchar(20),S_Album varchar(20),User_id int(2));”) except: pass
try: mycursor.execute(“create table Userdata(Userid int(2),Username varchar(20),Playlistname varchar(20));”) except: pass
mycursor.execute(‘select * from Songdata;’) output=mycursor.fetchall()
if output == []:
mycursor.execute('insert into Songdata values(01,"Come & go","Juice WRLD","Legends never die",11);') mycursor.execute('insert into Songdata values(02,"Superman","Eminem","The Eminem Show",21);') mycursor.execute('insert into Songdata values(03,"Worldstar money","joji","In tounges",11);') mycursor.execute('insert into Songdata values(04,"Water fountain","Alec Benjamin","Narrated For you",21);') mycursor.execute('insert into Songdata values(05,"Iraaday","Rovalio","IRAADAY",31);') mycursor.execute('insert into Songdata values(06,"Without me","Eminem","The Eminem Show",21);') mycursor.execute('insert into Songdata values(07,"Sahiba","Aditya Rikhari","Sahiba",31);') mycursor.execute('insert into Songdata values(08,"Brilliant Mind","Blanco","ReBourne",11);')
mycursor.execute(‘select * from Userdata;’) output=mycursor.fetchall() if output == []: mycursor.execute(‘insert into Userdata values(11,”dhairya”,”dumcore”);’) mycursor.execute(‘insert into Userdata values(21,”kavish”,”doremon”);’) mycursor.execute(‘insert into Userdata values(31,”tejas”,”padhai kar le”);’)
def fetchsongdata(): mycursor.execute(‘select * from Songdata’) return mycursor.fetchall()
def checkUserId(id): mycursor.execute(‘select * from Userdata;’) userIds = mycursor.fetchall() for user in userIds: if user[0] == id: return True return False
def insertSong(id): songdata = fetchsongdata() print(“”) songname = input(“Song name: “) artist = input(“Artist: “) album = input(“Album: “) mycursor.execute(f’insert into Songdata values({len(songdata)+1},”{songname}”,”{artist}”,”{album}”,{id});’) print(“Song inserted”) print(“”) mydb.commit()
def createUser(): mycursor.execute(‘select * from userdata’) userdata = mycursor.fetchall()
name = input("UserName: ") playlistName = input("Playlist: ") userId = int(f"{len(userdata)+1}1") mycursor.execute(f'insert into userdata values({userId},"{name}","{playlistName}")') mydb.commit() return userId
def printSongs(): print(“———————————————————-“) print(“Sr no. Song Name, Artist, Playlist, User Id”) for l in mycursor.fetchall(): for data in l: print(f”{data}, “, end= “”) print(“”) print(“”) print(“———————————————————-“)
————- project ——–
print(“——–Spotipy Songs Database——“)
userId = int(input(“Enter User id: “)) try: mycursor.execute(f”select Username from Userdata where Userid = {userId}”) print(f”Welcome {mycursor.fetchall()[0][0]} to our Song Database”)
except: pass
while True: if userId == 00: print(“Admin Login!”) func = int(input(“1. Fetch alln2. Wiew Usersn3. quit”)) print(”) if func == 1: mycursor.execute(f”select * from Songdata”) printSongs() if func == 2: mycursor.execute(f”select * from Userdata”) print(mycursor.fetchall()) if func == 3: exit() else: print(“Invalid Output”)
elif checkUserId(userId): func = int(input("1. Insert n2. Fetchn3. Dropn4. Quitn")) print("n") if func == 1: insertSong(userId) elif func == 2: mycursor.execute(f"select * from Songdata where User_id = '{userId}' ") print("----------------------------------------------------------") print("Sr no. Song Name, Artist, Playlist, User Id") for l in mycursor.fetchall(): for data in l: print(f"{data}, ", end= "") print("") print("") print("----------------------------------------------------------") elif func == 3: selection = input("which ID to drop: ") mycursor.execute(f"DELETE FROM Songdata WHERE s_id = {int(selection)};") mydb.commit() elif func == 4: print("Thanks for using the song database!") exit() else: print("Invalid Output") else: func = input("Create new user(y/n)").lower() if func == "y": userId = createUser() print(f"Your New userId is: {userId}") elif func == "n": exit() else: print("invalid output")
submitted by /u/InteractionWeekly308
[link] [comments]