Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/python
import random
import requests #import requests so the api code called can work
def greet(usrInput):
greetings = ["hello", "hi", "how are you", "sup", "whats up", "what's up", "hey", "howdy", "how r u"] #list of relevant terms
for word in greetings: #loops for every string in the list
if word == usrInput: #if the word in the list is the same as user input
return True #then return a value of true
def rec(usrInput):
recommend = ["recomend me music", "recomend music to me", "recommend","reccommend"]#list of relevant terms
for word in recommend:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True#then return a value of true
def lyric(usrInput):
lyrics = ["lyrics", "words", "lyric", "lyric finder"]#list of relevant terms
for word in lyrics:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True#then return a value of true
def chartSong(usrInput):
charts = ["chart songs", "charts song", "chart song", "charts songs", "songs in charts", "song in top chart", "songs in top charts", "song charts", "top song", "top charts" ]#list of relevant terms
for word in charts:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True#then return a value of true
def preftrack(usrInput):
preference = ["preference tracker", "previous music taste", "previous music preference", "past music preference", "track my music taste", "track music taste", "track my music preference", "track music preference"]#list of relevant terms
for word in preference:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True
def chartArtist(usrInput):
charts = ["chart artists", "charts artist", "chart artist", "charts artists", "artist in charts", "artist in top chart", "artists in top charts", "artist charts", "top artist"]#list of relevant terms
for word in charts:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True#then return a value of true
def artistbio(usrInput):
bio = ["tell me about", "tell me something about", "biography", "artist bio", "describe artist", "bio" ]#list of relevant terms
for word in bio:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True#then return a value of true
def question(usrInput):
qs = ["what can you do", "what are your features", "functions", "what can u do",]#list of relevant terms
for word in qs:#loops for every string in the list
if word in usrInput:#if the word in the list is the same as user input
return True#then return a value of true
def reply(): #prints random greeting
greetings = ["Hello :)", "Welcome!", "Greetings", "Hi",]#list of greetings
output = random.choice(greetings)#randomly picks a greeting
print(output) #outputs the random choice
def artistrec(): #runs artist recommending function and asks the user if they want to run it again
import artistrecc #import the code from an external file
artistrecc.my_func()#runs the feature
while True:#starts infinite loop
yesno = input("Would you like more recommended music?\n") #asks user if they want that feature again and records the answer
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno: #if they arent sure
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine what they said, if they said no then:
print("Ok, what would you like me to do?") #asks the user what they want it to do
break #ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine what they said, if they said yes then:
artistrecc.my_func()#run the feature again
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)# randomises the text telling the user to try again
print(output)#prints randomised message
def artistBio():#runs artist bio function and asks the user if they want to run it again
import artistbio#import the code from an external file
artistbio.main()#runs the feature
while True:#starts infinite loop
yesno = input("Would you like more artist bios?\n")#asks user if they want that feature again and records the answer
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno:
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine if they said no, if they said no then:
print("Ok, what would you like me to do?")#asks the user what they want it to do
break#ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine what they said, if they said yes then:
artistbio.main()#runs feature again
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)# randomises the text telling the user to try again
print(output)#outputs try again message
def lyricsapi():
import lyrics_api#import the code from an external file
lyrics_api.my_func()#runs the feature
while True: #starts infinite loop
yesno = input("Would you like to search for more lyrics?\n")#asks user if they want that feature again and records the answer
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno:
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine if they said no, if they said no then:
print("Ok, what would you like me to do?")#asks the user what they want it to do
break#ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine what they said, if they said yes then:
lyrics_api.my_func()#runs feature again
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)# randomises the text telling the user to try again
print(output)#outputs try again message
def chart_song():
import chart_songs#import the code from an external file
chart_songs.my_func()#runs the feature
while True: #starts infinite loop
yesno = input("Would you like to search for more top songs?\n")#asks user if they want that feature again and records the answer
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno:
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine if they said no, if they said no then:
print("Ok, what would you like me to do?")#asks the user what they want it to do
break#ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine what they said, if they said yes then:
chart_songs.my_func()#outputs try again message
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)# randomises the text telling the user to try again
print(output)#outputs try again message
def preferences():
import preferences#imports and runs the feature
while True: #starts infinite loop
yesno = input("Would you like to track your preferenc again?\n")#asks user if they want that feature again and records the answer
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno:
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine if they said no, if they said no then:
print("Ok, what would you like me to do?")#asks the user what they want it to do
break#ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine what they said, if they said yes then:
preferences.pref()
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)
print(output)#outputs try again message
def chart_artist():
import chart_artist#import the code from an external file
chart_artist.my_func()#runs the feature
while True: #starts infinite loop
yesno = input("Would you like to search for more top artist?\n")#asks user if they want that feature again and records the answer
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno:
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine if they said no, if they said no then:
print("Ok, what would you like me to do?")#asks the user what they want it to do
break#ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine what they said, if they said yes then:
chart_artist.my_func()#runs the feature again
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)
print(output)#outputs try again message
def askname():
global name
name = input("What's your name?\n")
print(name + ", thats a cool name. I'm the music chat bot")
while True:#starts infinite loop
yesno = input("Do you want to give me a name?\n").lower()#asks user if they want to give the bot a name
if "maybe" in yesno or "i dont know" in yesno or "i don't know" in yesno or "perhaps" in yesno:
print("Please make up your mind")
elif yesorno(yesno) == True:#calls function with the user input to determine if they said no, if they said no then:
print("Ok, what would you like me to do?")#asks the user what they want it to do
break#ends loop
elif yesorno(yesno) == False:#calls function with the user input to determine if they said no, if they said yes then:
newname = input("Ok! Type the name you want to call me: ")#asks user for new name of the bot
print("Hmm " + newname + "... I like it!")#print the new name
print("What would you like me to do?")#asks the user what they want it to do
break#ends loop
else:
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?"]
output = random.choice(confused)
print(output)#outputs try again message
def yesorno(yesno):#determines if the user input is saying yes or no
yes = ["yes", "yes please", "yep", "i do", "i would", "ok", "sure", "ye", "yeah", "aight", "alright"]#list of yes words
no = ["no", "no thanks" "nope", "i dont", "i wouldn't", "not", "nah", "nuh uh", "nay"]#list of no words
for word in no:#loops for every word in the no list
if word == yesno:#if the user input is in the no list
return True#return a value of true
for word in yes:#loops for every word in the yes list
if word == yesno:#if the user input is in the yes list
return False#return a value of false
def welcome():
print("Hello, welcome to music bot. ^-^")#welcomes user
def nlp():
confused = ["Sorry, I did not understand. Try and rephrase.", "I'm not sure what you're trying to say, please try again", "What do you mean?", "Sorry, what do you mean?"]#list of ways to ask the user to reword their request
output = random.choice(confused)#picks a random string from the list
print(output)#outputs that random response
def main():#main code
count = 0#resets count to zero
while True:#starts infinite loop
usrInput = input("").lower()
if usrInput in ["exit", "quit", "leave", "goodbye", "bye", "cya", "see you"]:#if the user says they want to quit
break#ends loop
elif greet(usrInput):#checks if user input is a greeting
reply()#calls feature to greet user
if count<1 :#if the user hasnt been asked already
askname()#calls function to ask user their name
count = count + 1#increases count so user doesn't get asked twice or more
elif rec(usrInput):#checks if user is asking for recommendation feature
artistrec()
elif lyric(usrInput):#checks if user is asking for lyrics
lyricsapi()
elif chartSong(usrInput):#checks if user is asking for song charts
chart_song()
elif preftrack(usrInput):#checks if user is asking for preference tracker
preferences()
elif chartArtist(usrInput):#checks if user is asking for artist charts
chart_artist()
elif artistbio(usrInput):#checks if user is asking for artist bio
artistBio()
elif question(usrInput):#checks if user is asking what the bot does
print("""I can recommend you artists, give you the top charts worldwide,
find lyrics, track your music taste over time and give you
info (short bios) on artists""")
else:
nlp()#calls function to say input was not understood
print("Goodbye")#goodbye message
quit()#ends code
welcome()#welcomes user
main()#runs main code