In [158]:
import requests
In [159]:
#Question 1
response = requests.get("https://api.spotify.com/v1/search?q=lil&type=artist&limit=50&market=US")
data = response.json()
In [160]:
type(data)
Out[160]:
In [161]:
data.keys()
Out[161]:
In [162]:
data['artists'].keys()
Out[162]:
In [163]:
artists = data['artists']['items']
In [164]:
for artist in artists:
print(artist['name'], artist['popularity'])
In [165]:
#Question 2 awnser.
for artist in artists:
print(artist['name'], artist['popularity'])
if len(artist['genres']) == 0:
print("no genres listed")
else:
genres = ", ".join(artist['genres'])
print("Genres list: ", genres)
In [166]:
most_popular_name = ""
most_popular_score = 0
for artist in artists:
#countring problem:
followers = artist['followers']
print(artist['name'], artist['popularity'])
print(artist['popularity'], "compering to", most_popular_score)
if artist['popularity'] > most_popular_score:
print("fund new one!")
if artist['name'] == "Lil Wayne":
print("oh, nice try", artist['name'])
else:
print("This is the new king!")
most_popular_name = artist['name']
most_popular_score = artist['popularity']
print(artist['name'], followers)
print('anwser for question 2')
print(most_popular_name," is the most popular of all the lil with", most_popular_score,"of score.")
In [167]:
most_followers_name = ""
most_followers_score = 0
artists = data['artists']['items']
for artist in artists:
total_followers = artist['followers']['total']
print(artist['name'], artist['popularity'], total_followers)
if total_followers > most_followers_score:
if artist['name'] == "Lil Wayne":
print("not you wayne")
else:
print('updating the new winner')
most_followers_name = artist['name']
most_followers_score = total_followers
print("who has more followers?")
print(most_followers_name,"is the winner and has arround", most_followers_score, "followers")
if most_followers_name != "Lil Yatchy":
print("Lil Yachty is not the winner in the followers category")
In [168]:
#Question 4 (firt part)
for artist in artists:
if artist['name'] == "Lil' Kim":
print("found lil kim")
print(artist['popularity'])
In [169]:
#Question 4 (second part)
lil_kim_popularity = 62
# AGGREGATION PROBLEM
more_popular_than_lil_kim = []
# THE LOOP
for artist in artists:
if artist['popularity'] > lil_kim_popularity:
print(artist['name'], "is MORE POPULAR with a score of", artist['popularity'])
more_popular_than_lil_kim.append(artist['name'])
new_list = ", ".join(more_popular_than_lil_kim)
print("Artist that are more popular than Lil Kim:", new_list)
In [170]:
for artist in artists:
print(artist['name'], artist['id'] )
In [171]:
#Artist chosen:
#Lil_Uzi_Vert_id = 4O15NlyKLIASxsJ0PrXPfz
#Lil_Dicky_id = 1tqhsYv8yBBdwANFNzHtcr
import requests
response = requests.get("https://api.spotify.com/v1/artists/4O15NlyKLIASxsJ0PrXPfz/top-tracks?country=US")
data2 = response.json()
In [172]:
type(data2)
Out[172]:
In [173]:
data2.keys()
Out[173]:
In [174]:
type(data2['tracks'])
Out[174]:
In [175]:
List_of_explicit_tracks= []
List_of_non_explicit_tracks= []
tracks = data2['tracks']
for track in tracks:
if track['explicit'] == True:
print(track['name'], "is explicit")
List_of_explicit_tracks.append(track['name'])
else:
print(track['name'],"with a popularity of", track['popularity'], "is not explicit")
List_of_non_explicit_tracks.append(track['name'])
print("#######")
print(len(List_of_explicit_tracks), "tracks of Lil Uzi are explicit",",",len(List_of_non_explicit_tracks), "tracks are not explicit")
In [176]:
lil_uzi_tracks = tracks
In [153]:
explicit_track_pop_total = 0
non_explicit_track_pop_total = 0
lil_uzi_list_explicit = []
lil_uzi_list_nonexplicit = []
for tracks in lil_uzi_tracks:
if tracks['explicit'] == True:
explicit_track_pop_total = explicit_track_pop_total + tracks['popularity']
lil_uzi_list_explicit.append(explicit_track_pop_total)
elif tracks['explicit'] == False:
non_explicit_track_pop_total = non_explicit_track_pop_total + tracks['popularity']
lil_uzi_list_nonexplicit.append(non_explicit_track_pop_total)
explicit_track_duration_total = 0
non_explicit_track_duration_total = 0
lil_uzi_list_explicit_dur = []
lil_uzi_list_nonexplicit_dur = []
for tracks in lil_uzi_tracks:
if tracks['explicit'] == True:
explicit_track_duration_total = explicit_track_duration_total + tracks['duration_ms']
lil_uzi_list_explicit_dur.append(explicit_track_duration_total)
elif tracks['explicit'] == False:
non_explicit_track_pop_total = non_explicit_track_duration_total + tracks['duration_ms']
lil_uzi_list_nonexplicit_dur.append(non_explicit_track_duration_total)
print("The average of popularity of explicit tracks:", float(sum(lil_uzi_list_explicit))/len(lil_uzi_list_explicit))
print("The average of popularity of non explicit tracks:",sum(lil_uzi_list_nonexplicit)) #We already now this is 0
print("The duration of explicit tracks in minutes:", sum(lil_uzi_list_explicit_dur)/60000)
In [ ]:
In [177]:
import requests
response = requests.get("https://api.spotify.com/v1/artists/1tqhsYv8yBBdwANFNzHtcr/top-tracks?country=US")
data4 = response.json()
lil_Dicky_tracks = data4
In [154]:
List_of_explicit_tracks2= []
List_of_non_explicit_tracks2= []
tracks2 = lil_Dicky_tracks['tracks']
for track in tracks2:
if track['explicit'] == True:
print(track['name'], "is explicit")
List_of_explicit_tracks2.append(track['name'])
elif tracks['explicit'] == False:
print(track['name'],"with a popularity of", track['popularity'], "is not explicit")
List_of_non_explicit_tracks2.append(track['name'])
print("#######")
print(len(List_of_explicit_tracks2), "tracks of Lil Dicky are explicit",",", len(List_of_non_explicit_tracks2), "tracks are not explicit")
In [182]:
explicit_track_pop_total2 = 0
non_explicit_track_pop_total2 = 0
lil_Dick_list_explicit = []
lil_Dick_list_nonexplicit = []
tracks3 = lil_Dicky_tracks['tracks']
for tracks in tracks3:
if tracks['explicit'] == True:
explicit_track_pop_total2 = explicit_track_pop_total2 + tracks['popularity']
lil_Dick_list_explicit.append(explicit_track_pop_total)
elif tracks['explicit'] == False:
non_explicit_track_pop_total2 = non_explicit_track_pop_total2 + tracks['popularity']
lil_Dick_list_nonexplicit.append(non_explicit_track_pop_total)
explicit_track_duration_total = 0
explicit_track_duration_total2 = 0
non_explicit_track_duration_total2 = 0
lil_Dick_list_explicit_dur = []
lil_Dick_list_nonexplicit_dur = []
tracks3 = lil_Dicky_tracks['tracks']
for tracks in tracks3:
if tracks['explicit'] == True:
explicit_track_duration_total2 = explicit_track_duration_total2 + tracks['duration_ms']
lil_Dick_list_explicit_dur.append(explicit_track_duration_total2)
elif tracks['explicit'] == False:
non_explicit_track_duration_total2 = non_explicit_track_duration_total2 + tracks['duration_ms']
lil_Dick_list_nonexplicit_dur.append(non_explicit_track_duration_total2)
print("The average of popularity of explicit tracks:", float(sum(lil_Dick_list_explicit))/len(lil_Dick_list_explicit))
print("The average of popularity of non explicit tracks:",sum(lil_Dick_list_nonexplicit)) #We already now this is 0
print("The duration of explicit tracks in minutes:", sum(lil_Dick_list_explicit_dur)/60000)
In [183]:
# BIGGIE DATA
response = requests.get('https://api.spotify.com/v1/search?query=Biggie&type=artist&limit=50&market=US')
Biggie_data = response.json()
In [184]:
# LIL'S DATA
response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&market=US')
Lil_data = response.json()
In [187]:
response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&market=US')
Lil_data = response.json()
Biggie_artists = Biggie_data['artists']['total']
Lil_artists = Lil_data['artists']['total']
print("There are", Biggie_artists, "artists named Biggie on Spotify and", Lil_artists, "named with Lil on it",)
In [190]:
Total_Download_Time_Biggie = Biggie_artists / 50 * 5
Total_Download_Time_Lil = Lil_artists / 50 * 5
print("It would take", round(Total_Download_Time_Biggie), "seconds to download all the Biggie artists and", round(Total_Download_Time_Lil), "seconds to download the Lil artists." )
In [193]:
Lil_artists_pop = Lil_data['artists']['items']
for popularity in Lil_artists_pop:
print(popularity['name'], popularity['popularity'])
In [194]:
Biggie_pop = Biggie_data['artists']['items']
for artist in Biggie_pop:
print(artist['name'], artist['popularity'])
In [195]:
Lil_artists_pop = Lil_data['artists']['items']
popularity_total = 0
for popularity in Lil_artists_pop:
popularity_total = popularity_total + popularity['popularity']
print("The average rating for the top 50 artists called Lil is:", round(popularity_total / 50))
Biggie_artists_pop = Biggie_data['artists']['items']
Biggie_popularity_total = 0
for popularity2 in Biggie_artists_pop:
Biggie_popularity_total = Biggie_popularity_total + popularity2['popularity']
print("The average rating for the top 50 artists called Biggie is:", round(Biggie_popularity_total / 50) )
In [ ]:
In [ ]: