import requests
import urllib
import matplotlib.pyplot as plt
from IPython.display import display , Image
from IPython.core.display import HTML
import requests
% matplotlib inline
Debugging with pdb
def display_image ( url ):
response = urllib . request . urlopen ( url ) . read ()
img = Image ( response , width = 200 )
display ( img )
display_image ( "https://i.ytimg.com/vi/z_AbfPXTKms/hqdefault.jpg" )
response = requests . get ( "https://api.spotify.com/v1/search?query=lil&offset=0&limit=20&type=artist" )
data = response . json ()
data . keys ()
data [ 'artists' ] . keys ()
dict_keys(['offset', 'total', 'previous', 'href', 'next', 'items', 'limit'])
artists = data [ 'artists' ][ 'items' ]
artists [ 0 ] . keys ()
dict_keys(['popularity', 'external_urls', 'name', 'followers', 'type', 'id', 'genres', 'href', 'uri', 'images'])
artists [ 0 ][ 'images' ]
[{'height': 1239,
'url': 'https://i.scdn.co/image/cf012139c3b8681b46a66bae70558a8a336ab231',
'width': 1000},
{'height': 793,
'url': 'https://i.scdn.co/image/fffd48d60e27901f6e9ce99423f045cb2b893944',
'width': 640},
{'height': 248,
'url': 'https://i.scdn.co/image/bf03141629c202e94b206f1374a39326a9d8c6ca',
'width': 200},
{'height': 79,
'url': 'https://i.scdn.co/image/521f99f2469883b8806a69a3a2487fdd983bd621',
'width': 64}]
#def display_artist_image(artist):
# try:
# #print("Trying to display an image for someone")
# display_image(artist['images'][0]['url'])
# #print("Displayed an image for that person")
# except:
# #print("Failed on", artist)
# pass
def display_artist_image ( artist ):
display_image ( artist [ 'images' ][ 0 ][ 'url' ])
unpopular_response = requests . get ( "https://api.spotify.com/v1/search?query=lil&offset=1200&limit=20&type=artist" )
unpopular_data = unpopular_response . json ()
unpopular_artists = unpopular_data [ 'artists' ][ 'items' ]
for artist in unpopular_artists :
try :
display_artist_image ( artist )
except :
print ( "Failed on" , artist [ 'name' ])
Failed on Lil Ruc
Failed on Lil Base
Failed on Lil Nitty
Failed on Lil Kmac
Failed on Lil Woody
Failed on Lil Muggsy
Failed on Lil Mbone
Failed on Lil Chan
Failed on Lil Cone
Failed on Lil Dramma