In [1]:
import requests
In [2]:
lil_response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&market=US&limit=50')
raw_lil_data=lil_response.json()
artists=raw_lil_data['artists']['items']
In [3]:
print('Here are 50 Lil-adjacent artists for you to peruse:')
artist_count=0
for artist in artists:
artist_count=artist_count+1
print(artist_count, artist['name'], artist['popularity'])
In [4]:
print('Here is that same list but with genres, maybe:')
for artist in artists:
if not artist['genres']:
print(artist['name'], 'stinks and has no genres')
else:
print(artist['name'], 'is', ", ".join(artist['genres']))
In [5]:
most_popular={'artist': '???', 'popularity': 0, 'followers': 0}
second_most_popular={'artist': '???', 'popularity': 0, 'followers': 0}
third_most_popular={'artist': '???', 'popularity': 0, 'followers': 0}
most_followers={'artist': '???', 'total': 0}
for artist in artists:
if artist['popularity'] > most_popular['popularity']:
most_popular['artist']=artist['name']
most_popular['popularity']=artist['popularity']
most_popular['followers']=artist['followers']['total']
elif artist['popularity'] > second_most_popular['popularity']:
second_most_popular['artist']=artist['name']
second_most_popular['popularity']=artist['popularity']
second_most_popular['followers']=artist['followers']['total']
elif artist['popularity'] > third_most_popular['popularity']:
third_most_popular['artist']=artist['name']
third_most_popular['popularity']=artist['popularity']
third_most_popular['followers']=artist['followers']['total']
if artist['followers']['total'] > most_followers['total']:
most_followers['artist']=artist['name']
most_followers['total']=artist['followers']['total']
print("The most popular Lil OTHER THAN (obviously) Lil Wayne is:", second_most_popular['artist'])
print("The next most popular Lil after that is:", third_most_popular['artist'])
if most_followers['artist']==most_popular['artist']:
print(most_followers['artist'], 'also has the most followers with', most_followers['total'])
else:
print("The artist with the most followers is", most_followers['artist'], 'with', most_followers['total'])
In [6]:
more_popular_than_lil_kim=[]
for artist in artists:
if int(artist['popularity']) > 62:
more_popular_than_lil_kim.append(artist['name'])
print("Here's a list of all the lil's more popular than Lil' Kim:", ", ".join(more_popular_than_lil_kim))
In [7]:
boozie_badazz=next((artist for artist in artists if artist['name']=="Boosie Badazz"), None)
lil_dicky=next((artist for artist in artists if artist['name']=="Lil Dicky"), None)
response=requests.get('https://api.spotify.com/v1/artists/'+boozie_badazz['id']+'/top-tracks?country=US')
boozie_badazz_top=response.json()
response=requests.get('https://api.spotify.com/v1/artists/'+lil_dicky['id']+'/top-tracks?country=US')
lil_dicky_top=response.json()
print("The two best lil's are Boozie Badazz and Lil Dicky, for what should be obvious reasons.")
print("Here is a list of Boozie Badazz's top tracks:")
for track in boozie_badazz_top['tracks']:
print(track['name'])
print()
print("And now here is the same manner of thing but with Lil Dicky:")
for track in lil_dicky_top['tracks']:
print(track['name'])
In [41]:
explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
non_explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
for track in boozie_badazz_top['tracks']:
if track['explicit']:
explicit['track_total']=explicit['track_total']+1
explicit['pop_total']=explicit['pop_total']+track['popularity']
explicit['dur_total']=explicit['dur_total']+track['duration_ms']
else:
non_explicit['track_total']=non_explicit['track_total']+1
non_explicit['pop_total']=non_explicit['pop_total']+track['popularity']
non_explicit['dur_total']=non_explicit['dur_total']+track['duration_ms']
if not explicit['track_total']:
print("Boozie Badazz is a gentleman with no naughty tracks")
else:
print("Boozie Badass has", explicit['track_total'], "explicit tracks, totaling", format(explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", explicit['pop_total']/explicit['track_total'])
if not non_explicit['track_total']:
print("Boozie Badazz struggles making songs sans swears and therefore has none")
else:
print("Boozie Badass has", non_explicit['track_total'], "non-explicit tracks, totaling", format(non_explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", non_explicit['pop_total']/non_explicit['track_total'])
explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
non_explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
for track in lil_dicky_top['tracks']:
if track['explicit']:
explicit['track_total']=explicit['track_total']+1
explicit['pop_total']=explicit['pop_total']+track['popularity']
explicit['dur_total']=explicit['dur_total']+track['duration_ms']
else:
non_explicit['track_total']=non_explicit['track_total']+1
non_explicit['pop_total']=non_explicit['pop_total']+track['popularity']
non_explicit['dur_total']=non_explicit['dur_total']+track['duration_ms']
if not explicit['track_total']:
print("Lil Dicky is a gentleman with no naughty tracks")
else:
print("Lil Dicky has", explicit['track_total'], "explicit tracks, totaling", format(explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", explicit['pop_total']/explicit['track_total'])
if not non_explicit['track_total']:
print("Lil Dicky struggles making songs sans swears and therefore has none")
else:
print("Lil Dicky has", non_explicit['track_total'], "non-explicit tracks, totaling", format(non_explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", non_explicit['pop_total']/non_explicit['track_total'])
In [66]:
lil_response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&limit=50')
raw_lil_data=lil_response.json()
top_50_lils=raw_lil_data['artists']['items']
biggie_response = requests.get('https://api.spotify.com/v1/search?q=Biggie&type=artist&limit=50')
raw_biggie_data=biggie_response.json()
top_50_biggies=raw_biggie_data['artists']['items']
In [61]:
print("There are", raw_lil_data['artists']['total'], "Lils, and", raw_biggie_data['artists']['total'], "Biggies")
print("That's way more Lils")
print("Requesting 1 Lil every 5 seconds is silly but it would also take you", format(raw_lil_data['artists']['total']*5/60, '.2f'), "minutes to get them all")
print("Biggies, meanwhile, would take", format(raw_biggie_data['artists']['total']*5/60, '.2f'), "minutes")
In [72]:
lil_pop={'count': 0, "total": 0}
biggie_pop={'count': 0, "total": 0}
for lil in top_50_lils:
lil_pop['count']=lil_pop['count']+1
lil_pop['total']=lil_pop['total']+lil['popularity']
print("Your average, everyday Lil has a popularity of", lil_pop['total']/lil_pop['count'])
for biggie in top_50_biggies:
biggie_pop['count']=biggie_pop['count']+1
biggie_pop['total']=biggie_pop['total']+biggie['popularity']
print("Your average, everyday Biggie has a popularity of", format(biggie_pop['total']/biggie_pop['count'], '.2f'))
print("The lils are clearly winning this war")
In [ ]: