Grade: 6 / 8 -- check for TA-COMMENTS


In [1]:
import requests

In [2]:
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
#Lil_data

In [3]:
Lil_data.keys()


Out[3]:
dict_keys(['artists'])

In [4]:
Lil_data['artists'].keys()


Out[4]:
dict_keys(['href', 'total', 'items', 'offset', 'limit', 'next', 'previous'])

In [5]:
Lil_artists = Lil_data['artists']['items']

1.Searching and Printing a List of 50 'Lil' Musicians

With "Lil Wayne" and "Lil Kim" there are a lot of "Lil" musicians. Do a search and print a list of 50 that are playable in the USA (or the country of your choice), along with their popularity score.


In [6]:
#With "Lil Wayne" and "Lil Kim" there are a lot of "Lil" musicians. Do a search and print a list of 50 
#that are playable in the USA (or the country of your choice), along with their popularity score.

count =0
for artist in Lil_artists:
    count += 1
    print(count,".", artist['name'],"has the popularity of", artist['popularity'])


1 . Lil Wayne has the popularity of 86
2 . Lil Yachty has the popularity of 72
3 . Lil Uzi Vert has the popularity of 73
4 . Lil Dicky has the popularity of 68
5 . Boosie Badazz has the popularity of 67
6 . Lil Jon has the popularity of 72
7 . King Lil G has the popularity of 61
8 . Lil Durk has the popularity of 60
9 . Lil Jon & The East Side Boyz has the popularity of 60
10 . Lil Bibby has the popularity of 54
11 . G Herbo has the popularity of 53
12 . Lil Rob has the popularity of 50
13 . Lil Reese has the popularity of 50
14 . Lil Keke has the popularity of 48
15 . Bow Wow has the popularity of 57
16 . Lil Scrappy has the popularity of 48
17 . Lil Wyte has the popularity of 50
18 . Lil Blood has the popularity of 45
19 . Lil Snupe has the popularity of 45
20 . Lil Mama has the popularity of 45
21 . Lil B has the popularity of 44
22 . Lil' Kim has the popularity of 62
23 . Lil Cuete has the popularity of 40
24 . Lil Phat has the popularity of 39
25 . Lil Debbie has the popularity of 43
26 . Lil Twist has the popularity of 39
27 . Lil Trill has the popularity of 37
28 . Lil Boom has the popularity of 39
29 . Lil Twon has the popularity of 37
30 . Lil AJ has the popularity of 37
31 . Lil Lonnie has the popularity of 37
32 . Lil Goofy has the popularity of 35
33 . Lil Haiti has the popularity of 36
34 . Mr. Lil One has the popularity of 36
35 . Lil Cray has the popularity of 35
36 . Lil Flash has the popularity of 38
37 . Lil Silva has the popularity of 43
38 . Lil Kesh has the popularity of 39
39 . Lil Rue has the popularity of 34
40 . Lil Yase has the popularity of 34
41 . Lil Eddie has the popularity of 41
42 . Lil Wayne, DJ Drama has the popularity of 35
43 . Lil Suzy has the popularity of 34
44 . Lil Mouse has the popularity of 34
45 . Lil C has the popularity of 33
46 . Lil Rick has the popularity of 39
47 . Lil June has the popularity of 32
48 . Lil E has the popularity of 34
49 . Lil Fate has the popularity of 34
50 . Lil' Flip has the popularity of 49

2 Genres Most Represented in the Search Results

What genres are most represented in the search results? Edit your previous printout to also display a list of their genres in the format "GENRE_1, GENRE_2, GENRE_3". If there are no genres, print "No genres listed".


In [79]:
# What genres are most represented in the search results? Edit your previous printout to also display a list of their genres 
#in the format "GENRE_1, GENRE_2, GENRE_3". If there are no genres, print "No genres listed".
#Tip: "how to join a list Python" might be a helpful search
# if len(artist['genres']) == 0 )
# print ("no genres")
# else:
#     genres = ", ".join(artist['genres'])

genre_list = []
genre_loop = Lil_data['artists']['items']

for item in genre_loop:
    #print(item['genres'])
    item_gen = item['genres']
    for i in item_gen:
        genre_list.append(i)
#print(sorted(genre_list))

#COUNTING the most 

genre_counter = {}
for word in genre_list:
    if word in genre_counter:
        genre_counter[word] += 1
    else:
        genre_counter[word] = 1
popular_genre = sorted(genre_counter, key = genre_counter.get, reverse = True)
top_genre = popular_genre[:1]
print("The genre most represented is", top_genre)

#COUNTING the most with count to confirm

from collections import Counter
count = Counter(genre_list)
most_count = count.most_common(1)
print("The genre most represented and the count are", most_count)


print("-----------------------------------------------------")
    


for artist in Lil_artists:
    num_genres = 'no genres listed'
    if len(artist['genres']) > 0:
        num_genres= str.join(',', (artist['genres']))
    print(artist['name'],"has the popularity of", artist['popularity'], ", and has", num_genres, "under genres")


The genre most represented is ['dirty south rap']
The genre most represented and the count are [('dirty south rap', 4)]
-----------------------------------------------------
Lil Wayne has the popularity of 86 , and has dirty south rap,pop rap,southern hip hop,trap music under genres
Lil Yachty has the popularity of 72 , and has no genres listed under genres
Lil Uzi Vert has the popularity of 72 , and has no genres listed under genres
Lil Dicky has the popularity of 68 , and has no genres listed under genres
Boosie Badazz has the popularity of 67 , and has no genres listed under genres
Lil Jon has the popularity of 72 , and has crunk,dirty south rap,southern hip hop under genres
King Lil G has the popularity of 61 , and has no genres listed under genres
Lil Durk has the popularity of 60 , and has no genres listed under genres
Lil Jon & The East Side Boyz has the popularity of 60 , and has no genres listed under genres
Lil Bibby has the popularity of 54 , and has no genres listed under genres
G Herbo has the popularity of 53 , and has no genres listed under genres
Lil Rob has the popularity of 50 , and has chicano rap,latin hip hop under genres
Lil Reese has the popularity of 50 , and has no genres listed under genres
Lil Keke has the popularity of 48 , and has no genres listed under genres
Bow Wow has the popularity of 57 , and has hip pop,pop rap under genres
Lil Scrappy has the popularity of 48 , and has crunk,dirty south rap,southern hip hop,trap music under genres
Lil Wyte has the popularity of 50 , and has juggalo under genres
Lil Blood has the popularity of 45 , and has no genres listed under genres
Lil Snupe has the popularity of 45 , and has no genres listed under genres
Lil Mama has the popularity of 45 , and has hip pop under genres
Lil B has the popularity of 44 , and has no genres listed under genres
Lil' Kim has the popularity of 62 , and has hip pop under genres
Lil Cuete has the popularity of 40 , and has chicano rap under genres
Lil Phat has the popularity of 39 , and has no genres listed under genres
Lil Debbie has the popularity of 43 , and has no genres listed under genres
Lil Twist has the popularity of 39 , and has jerk under genres
Lil Trill has the popularity of 37 , and has deep trap under genres
Lil Twon has the popularity of 38 , and has no genres listed under genres
Lil AJ has the popularity of 37 , and has no genres listed under genres
Lil Lonnie has the popularity of 37 , and has no genres listed under genres
Lil Boom has the popularity of 35 , and has no genres listed under genres
Lil Goofy has the popularity of 35 , and has no genres listed under genres
Mr. Lil One has the popularity of 36 , and has chicano rap under genres
Lil Haiti has the popularity of 36 , and has no genres listed under genres
Lil Flash has the popularity of 38 , and has no genres listed under genres
Lil Kesh has the popularity of 39 , and has no genres listed under genres
Lil Cray has the popularity of 35 , and has no genres listed under genres
Lil Silva has the popularity of 43 , and has no genres listed under genres
Lil Rue has the popularity of 34 , and has no genres listed under genres
Lil Eddie has the popularity of 41 , and has no genres listed under genres
Lil Yase has the popularity of 33 , and has no genres listed under genres
Lil Wayne, DJ Drama has the popularity of 35 , and has no genres listed under genres
Lil Suzy has the popularity of 34 , and has freestyle under genres
Lil Mouse has the popularity of 34 , and has no genres listed under genres
Lil C has the popularity of 33 , and has no genres listed under genres
Lil Rick has the popularity of 39 , and has soca under genres
Lil June has the popularity of 32 , and has no genres listed under genres
Lil E has the popularity of 34 , and has no genres listed under genres
Lil Fate has the popularity of 34 , and has no genres listed under genres
Lil' Flip has the popularity of 49 , and has crunk,dirty south rap under genres

More Spotify - LIL' GRAPHICS

Use Excel, Illustrator or something like https://infogr.am/ to make a graphic about the Lil's, or the Lil's vs. the Biggies. Just a simple bar graph of their various popularities sounds good to me. Link to the Line Graph of Lil's Popularity chart

Lil Popularity Graph


In [7]:
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
#Lil_data

Use a for loop to determine who BESIDES Lil Wayne has the highest popularity rating. Is it the same artist who has the largest number of followers?


In [9]:
#Use a for loop to determine who BESIDES Lil Wayne has the highest popularity rating. 
#Is it the same artist who has the largest number of followers?
name_highest = ""
name_follow =""
second_high_pop = 0
highest_pop = 0
high_follow = 0
for artist in Lil_artists:
    if (highest_pop < artist['popularity']) & (artist['name'] != "Lil Wayne"):
        #second_high_pop = highest_pop
        #name_second = artist['name']
        highest_pop = artist['popularity']
        name_highest = artist['name']

    if (high_follow < artist['followers']['total']):
        high_follow = artist ['followers']['total']
        name_follow = artist['name']
    
    #print(artist['followers']['total'])

print(name_highest, "has the second highest popularity, which is", highest_pop)
print(name_follow, "has the highest number of followers:", high_follow)
#print("the second highest popularity is", second_high_pop)


Lil Yachty has the second highest popularity, which is 72
Lil Wayne has the highest number of followers: 2623705

In [8]:
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
#Lil_data

In [9]:
Lil_artists = Lil_data['artists']['items']
#Print a list of Lil's that are more popular than Lil' Kim.
count = 0
for artist in Lil_artists:
    if artist['popularity'] > 62:
        count+=1
        print(count, artist['name'],"has the popularity of", artist['popularity'])
        
    #else:
        #print(artist['name'], "is less popular with a score of", artist['popularity'])


1 Lil Wayne has the popularity of 86
2 Lil Yachty has the popularity of 72
3 Lil Uzi Vert has the popularity of 73
4 Lil Dicky has the popularity of 68
5 Boosie Badazz has the popularity of 67
6 Lil Jon has the popularity of 72

5.Two Favorite Lils and Their Top Tracks


In [17]:
response = requests.get("https://api.spotify.com/v1/search?query=Lil&type=artist&limit=2&country=US")
data = response.json()
for artist in Lil_artists:
    #print(artist['name'],artist['id'])
    if artist['name'] == "Lil Wayne":
        wayne = artist['id']
        print(artist['name'], "id is",wayne) 
        
    if artist['name'] == "Lil Yachty":
        yachty = artist['id']
        print(artist['name'], "id is", yachty)


Lil Wayne id is 55Aa2cqylxrFIXC767Z865
Lil Yachty id is 6icQOAFXDZKsumw3YXyusw

In [18]:
#Pick two of your favorite Lils to fight it out, and use their IDs to print out their top tracks.
#Tip: You're going to be making two separate requests, be sure you DO NOT save them into the same variable.
response = requests.get("https://api.spotify.com/v1/artists/" +wayne+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
print("Lil Wayne's top tracks are: ")
for track in tracks:
    print("-", track['name'])
print("-----------------------------------------------")

response = requests.get("https://api.spotify.com/v1/artists/" +yachty+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
print("Lil Yachty 's top tracks are: ")
for track in tracks:
    print("-", track['name'])


Lil Wayne's top tracks are: 
- Forever
- Nothing But Trouble - Instagram Models
- 6 Foot 7 Foot
- A Milli
- Right Above It
- Lollipop
- Love Me
- Rich As Fuck
- Mirror
- Believe Me
-----------------------------------------------
Lil Yachty 's top tracks are: 
- One Night (Extended)
- Minnesota (Remix) [feat. Quavo, Skippa da Flippa & Young Thug]
- Wanna Be Us (feat. Burberry Perry)
- Intro (Just Keep Swimming)
- Up Next 2 (feat. Big Brutha Chubba & Byou)
- Good Day (feat. Skippa da Flippa)
- Not My Bro
- Fucked Over
- Out Late
- Interlude

6. Average Popularity of My Fav Musicians (Above) for Their explicit songs vs. their non-explicit songs

Will the world explode if a musicians swears? Get an average popularity for their explicit songs vs. their non-explicit songs. How many minutes of explicit songs do they have? Non-explicit?


In [28]:
response = requests.get("https://api.spotify.com/v1/artists/" +yachty+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
#print(tracks)

In [29]:
#for track in tracks:
    #print(track.keys())

In [27]:
#Get an average popularity for their explicit songs vs. their non-explicit songs. 
#How many minutes of explicit songs do they have? Non-explicit?
# How explicit is Lils?

response = requests.get("https://api.spotify.com/v1/artists/" +yachty+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
# counter for tracks for explicit and clean
track_count = 0 
clean_count = 0
#counter to find avg popularity
popular_exp = 0
popular_clean = 0
#counter for avg time in minutes are below:
timer = 0
data_timer = 0
timer_clean = 0

for track in tracks:
    print("The track,", track['name'],", with the id",track['id'], "is", track['explicit'],"for explicit content, and has the popularity of", track['popularity'])
    track_id = track['id']
    time_ms = track['duration_ms']
    
    # TA-COMMENT: (-1) If what is true? "if True" will always evaluate to True.... 
    if True:
        track_count = track_count + 1
        popular_exp = popular_exp + track['popularity'] # TA-COMMENT: What is this supposed to capture? 
        # It HAPPENS to be the case that all the tracks are explicit, but if that were not true, would this be correct?
        
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_track = response.json()
        print("and has the duration of", data_track['duration_ms'], "milli seconds.")
        timer = timer + time_ms
        timer_minutes = ((timer / (1000*60)) % 60)
    if not track['explicit']:
        clean_count = clean_count + 1
        popular_clean = popular_clean + track['popularity']
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_tracks = response.json()
        timer_clean = timer_clean + time_ms
        timer_minutes_clean = ((data_timer / (1000*60)) % 60)
        print(", and has the duration of", timer_minutes_clean, "minutes")
        
print("------------------------------------")
avg_pop =  popular_exp / track_count
print("I have found", track_count, "tracks, and has the average popularity of", avg_pop, "and has the average duration of", timer_minutes,"minutes and", clean_count, "are clean")

#print("Overall, I discovered", track_count, "tracks")
#print("And", clean_count, "were non-explicit")
#print("Which means", , " percent were clean for Lil Wayne")


The track, One Night (Extended) , with the id 0l4EfZzVD0LyJhibHIIVxo is True for explicit content, and has the popularity of 77
and has the duration of 243269 milli seconds.
The track, Minnesota (Remix) [feat. Quavo, Skippa da Flippa & Young Thug] , with the id 7dTJQN1w1M79haPESIZ3zr is True for explicit content, and has the popularity of 68
and has the duration of 268114 milli seconds.
The track, Wanna Be Us (feat. Burberry Perry) , with the id 5xi6EyeIvVr6cCg44OZeEl is True for explicit content, and has the popularity of 63
and has the duration of 171899 milli seconds.
The track, Intro (Just Keep Swimming) , with the id 0cBD9mCJ3gFVNJdW2orLhz is True for explicit content, and has the popularity of 59
and has the duration of 252369 milli seconds.
The track, Up Next 2 (feat. Big Brutha Chubba & Byou) , with the id 2aJnTtI2KlV7Owx7tA63s8 is True for explicit content, and has the popularity of 57
and has the duration of 178046 milli seconds.
The track, Good Day (feat. Skippa da Flippa) , with the id 2e3oiurGwx1ueG0e18dGW6 is True for explicit content, and has the popularity of 56
and has the duration of 198092 milli seconds.
The track, Not My Bro , with the id 6K80Xw3GOaKguaHM0bQAzx is True for explicit content, and has the popularity of 56
and has the duration of 143598 milli seconds.
The track, Fucked Over , with the id 6U5OUBzrgftbUx1kVM4fH8 is True for explicit content, and has the popularity of 55
and has the duration of 175262 milli seconds.
The track, Out Late , with the id 3HIr5rowFdybrJxukOXlS5 is True for explicit content, and has the popularity of 55
and has the duration of 160037 milli seconds.
The track, Interlude , with the id 27dNwrgG4GoJrhloMrJMJJ is True for explicit content, and has the popularity of 54
and has the duration of 78915 milli seconds.
------------------------------------
I have found 10 tracks, and has the average popularity of 60.0 and has the average duration of 31.160016666666667 minutes and 0 are clean

In [1]:
# TA-COMMENT: example of what happens if you do just "if True" as in the code above. 
if True: 
    print("hello")


hello

In [30]:
# TA-COMMENT: Same commends apply here. 
#Get an average popularity for their explicit songs vs. their non-explicit songs. 
#How many minutes of explicit songs do they have? Non-explicit?
# How explicit is Lils?

response = requests.get("https://api.spotify.com/v1/artists/" +wayne+ "/top-tracks?country=US")
data = response.json()
# counter for tracks for explicit and clean
track_count = 0 
clean_count = 0
#counter to find avg popularity
popular_exp = 0
popular_clean = 0
#counter for avg time in minutes are below:
timer = 0
#data_timer = 0
timer_clean = 0

for track in tracks:
    print("The track,", track['name'],", with the id",track['id'], "is", track['explicit'],"for explicit content, and has the popularity of", track['popularity'])
    track_id = track['id']
    time_ms = data_track['duration_ms']
    if True:
        track_count = track_count + 1
        popular_exp = popular_exp + track['popularity']
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_track = response.json()
        print("and has the duration of", data_track['duration_ms'], "milli seconds.")
        timer = timer + time_ms
        timer_minutes = ((timer / (1000*60)) % 60)
    if not track['explicit']:
        clean_count = clean_count + 1
        popular_clean = popular_clean + track['popularity']
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_tracks = response.json()
        timer_clean = timer_clean + time_ms
        timer_minutes_clean = ((data_timer / (1000*60)) % 60)
        print(", and has the duration of", timer_minutes_clean, "minutes")
        
print("------------------------------------")
avg_pop =  popular_exp / track_count
print("I have found", track_count, "tracks, and has the average popularity of", avg_pop, "and has the average duration of", timer_minutes,"minutes and", clean_count, "are clean")

#print("Overall, I discovered", track_count, "tracks")
#print("And", clean_count, "were non-explicit")
#print("Which means", , " percent were clean for Lil Wayne")


The track, One Night (Extended) , with the id 0l4EfZzVD0LyJhibHIIVxo is True for explicit content, and has the popularity of 77
and has the duration of 243269 milli seconds.
The track, Minnesota (Remix) [feat. Quavo, Skippa da Flippa & Young Thug] , with the id 7dTJQN1w1M79haPESIZ3zr is True for explicit content, and has the popularity of 68
and has the duration of 268114 milli seconds.
The track, Wanna Be Us (feat. Burberry Perry) , with the id 5xi6EyeIvVr6cCg44OZeEl is True for explicit content, and has the popularity of 63
and has the duration of 171899 milli seconds.
The track, Intro (Just Keep Swimming) , with the id 0cBD9mCJ3gFVNJdW2orLhz is True for explicit content, and has the popularity of 59
and has the duration of 252369 milli seconds.
The track, Up Next 2 (feat. Big Brutha Chubba & Byou) , with the id 2aJnTtI2KlV7Owx7tA63s8 is True for explicit content, and has the popularity of 57
and has the duration of 178046 milli seconds.
The track, Good Day (feat. Skippa da Flippa) , with the id 2e3oiurGwx1ueG0e18dGW6 is True for explicit content, and has the popularity of 56
and has the duration of 198092 milli seconds.
The track, Not My Bro , with the id 6K80Xw3GOaKguaHM0bQAzx is True for explicit content, and has the popularity of 56
and has the duration of 143598 milli seconds.
The track, Fucked Over , with the id 6U5OUBzrgftbUx1kVM4fH8 is True for explicit content, and has the popularity of 55
and has the duration of 175262 milli seconds.
The track, Out Late , with the id 3HIr5rowFdybrJxukOXlS5 is True for explicit content, and has the popularity of 55
and has the duration of 160037 milli seconds.
The track, Interlude , with the id 27dNwrgG4GoJrhloMrJMJJ is True for explicit content, and has the popularity of 54
and has the duration of 78915 milli seconds.
------------------------------------
I have found 10 tracks, and has the average popularity of 60.0 and has the average duration of 31.160016666666667 minutes and 0 are clean

7a. Number of Biggies and Lils

Since we're talking about Lils, what about Biggies? How many total "Biggie" artists are there? How many total "Lil"s? If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?


In [31]:
#How many total "Biggie" artists are there? How many total "Lil"s? 
#If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?

biggie_response = requests.get('https://api.spotify.com/v1/search?query=biggie&type=artist&country=US')
biggie_data = biggie_response.json()
biggie_artists = biggie_data['artists']['total']
print("Total number of Biggie artists are", biggie_artists)

lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&country=US')
lil_data = lil_response.json()
lil_artists = lil_data['artists']['total']
print("Total number of Lil artists are", lil_artists)


Total number of Biggie artists are 50
Total number of Lil artists are 4510

7b. Time to Download All Information on Lil and Biggies


In [22]:
#If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?

limit_download = 50
biggie_artists = biggie_data['artists']['total']
Lil_artist = Lil_data['artists']['total']

#1n 5 sec = 50
#in 1 sec = 50 / 5 req = 10 no, for 1 no, 1/10 sec
# for 4501 = 4501/10 sec
# for 49 49/ 10 sec

big_count = biggie_artists/10
lil_count = Lil_artist / 10

print("It would take", big_count, "seconds for Biggies, where as it would take", lil_count,"seconds for Lils" )

# TA-COMMENT: (-1) If one request takes 5 seconds, then 50 requests would take (50 * 5) seconds 
# (one request for each 'Biggie')
# So, 4510 Lil artists would take 4510 * 5 seconds


It would take 5.0 seconds for Biggies, where as it would take 451.0 seconds for Lils

In [19]:
#Out of the top 50 "Lil"s and the top 50 "Biggie"s, who is more popular on average?

biggie_response = requests.get('https://api.spotify.com/v1/search?query=biggie&type=artist&limit=50&country=US')
biggie_data = biggie_response.json()

biggie_artists = biggie_data['artists']['items']
big_count_pop = 0
for artist in biggie_artists:
    #count_pop = artist['popularity']
    big_count_pop = big_count_pop + artist['popularity']
print("Biggie has a total popularity of ", big_count_pop)
big_pop = big_count_pop / 49
print("Biggie is on an average", big_pop,"popular")

#Lil
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
Lil_artists = Lil_data['artists']['items']
lil_count_pop = 0
for artist in Lil_artists:
    count_pop_lil = artist['popularity']
    lil_count_pop = lil_count_pop + count_pop_lil
lil_pop = lil_count_pop / 50
print("Lil is on an average", lil_pop,"popular")


Biggie has a total popularity of  193
Biggie is on an average 3.938775510204082 popular
Lil is on an average 46.16 popular

In [ ]: