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

Rubber Duck Debugging

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")

jpeg

response = requests.get("https://api.spotify.com/v1/search?query=lil&offset=0&limit=20&type=artist")
data = response.json()
data.keys()
dict_keys(['artists'])
data['artists'].keys()
dict_keys(['total', 'offset', 'previous', 'items', 'href', 'limit', 'next'])
artists = data['artists']['items']
artists[0].keys()
dict_keys(['external_urls', 'images', 'genres', 'id', 'name', 'popularity', 'type', 'href', 'followers', 'uri'])
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):
    if len(artist['images']) >= 1:
        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:
#    display_artist_image(artist)
unpopular_artists = unpopular_data['artists']['items']
display_artist_image(unpopular_artists[0])

jpeg

for artist in unpopular_artists:
    display_artist_image(artist)

jpeg

jpeg

jpeg

jpeg

jpeg

jpeg

jpeg

jpeg