Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ChatBot/music.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (34 sloc)
1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import webbrowser | |
from connection import connection | |
def Music(): | |
connect = connection() | |
cursor = connect.cursor() | |
option = int(input("Press 1 to play music\nPress 2 to add music\n Option: ")) | |
if option == 1: | |
music = input("Which music do you want to listen? \nMusic: ") | |
music = music.lower() | |
sql = 'SELECT link FROM music WHERE name = "' + music + '"' | |
cursor.execute(sql) | |
connect.commit() | |
myresult = cursor.fetchall() | |
for x in myresult: | |
new = 2 | |
url = str(x) | |
url = url[2:] | |
url = url[:-3] | |
print(url) | |
webbrowser.open(str(url), new=new) | |
break | |
else: | |
sql = "INSERT INTO music (name, link) VALUES (%s, %s)" | |
connect.commit() | |
name = input("Name of the music: ") | |
name = name.lower() | |
link = input("Link: ") | |
link = link[8:] | |
link = str(link) | |
val = (name, link) | |
cursor.execute(sql, val) | |
connect.commit() | |
#########Start Code Here######### | |
#Music() |