Skip to content
Permalink
Browse files
fixed bugs
  • Loading branch information
elbezral committed Nov 28, 2020
1 parent c6b4f6f commit 31765a6774c25a5035ab883601ef6bc957bf9e43
Showing 1 changed file with 19 additions and 11 deletions.
@@ -1,29 +1,37 @@
#Code by: Mazikeen El Bezra, ID: 10832578, documentation used: https://developer.musixmatch.com/documentation, https://requests.readthedocs.io/en/master/, adapted from: https://www.youtube.com/watch?v=WFRzKmpepj4&t=1108s
''' function to reccomend a requested number of artists based on the users artist choice and return their rating if user wanted '''
def my_func():
import requests
import requests #import request package which is used to import HTTP requests
import json

key= "&apikey=352a18cc5baa9cd34bd6fc0aa20c3401"
key= "&apikey=352a18cc5baa9cd34bd6fc0aa20c3401" #API key used to access the music API
url="https://api.musixmatch.com/ws/1.1/"

print("Welcome to reccomending artists!\n")
artist= input("Who's yout inspiration?")

#artistid
#creates a URL request using the user's inputs
artistsearch= url + 'artist.search' + '?format=json&callback=callback' + '&q_artist=' + artist + '&page=1&page_size=1' + key
request = requests.get(artistsearch)
data = request.json()
artist_id=str(data['message']['body']['artist_list'][0]['artist']['artist_id'])

#related ones
request = requests.get(artistsearch) #sends a GET request to the specified url to get data from server
data = request.json() #parse it as a JSON object
artist_id=str(data['message']['body']['artist_list'][0]['artist']['artist_id']) #retrieves the artist id from json and saves it as a variable
number= str(input('How many reccomendations would you like?'))
related= url + 'artist.related.get'+ '?format=json&callback=callback' + '&artist_id=' + artist_id + '&page_size=' +number + key
request = requests.get(related)
data = request.json()
#calls api method needed
related= url + 'artist.related.get'+ '?format=json&callback=callback' + '&artist_id=' + artist_id + '&page_size=' +number + key

request = requests.get(related) #sends a GET request to the specified url to get data from server
data = request.json() #parse it as a JSON object
#for loop used to access the 'artist list' object and return its object values
for i in data['message']['body']['artist_list']:
print(i['artist']['artist_name'])
twit= input("would you like their rating? enter y for yes or n for no")
twit= input("would you like their rating? enter y for yes or n for no") #ask if they want the rating
if twit=='y':
#loop to access 'artist list' object and return the rating
for i in data['message']['body']['artist_list']:
print(i['artist']['artist_rating'])
else:
pass

my_func()
#End of code by mazikeen

0 comments on commit 31765a6

Please sign in to comment.