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

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(['limit', 'items', 'previous', 'offset', 'href', 'next', 'total'])
artists = data['artists']['items']
artists[0].keys()
dict_keys(['followers', 'popularity', 'type', 'uri', 'name', 'href', 'external_urls', 'genres', 'images', 'id'])
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):
    print("Inside of display_artist_image")
    #import pdb; pdb.set_trace()
    if len(artist['images']) < 1:
        return
    display_image(artist['images'][0]['url'])

A simply pdb example

print("Starting")

my_int = 10
my_string = "Cats"
my_list = [45, 23, 12, "Animal"]

import pdb; pdb.set_trace()

my_dicts = [
    { 'name': "Samuel", 'age': 109 },
    { 'name': "Samantha", 'age': 109 }
]
my_str = "Dogs"

import pdb; pdb.set_trace()

print("Finished")
Starting
--Return--
> <ipython-input-27-551fea013d11>(7)<module>()->None
-> import pdb; pdb.set_trace()
(Pdb) my_int
10
(Pdb) my_dicts
[{'age': 109, 'name': 'Samuel'}, {'age': 109, 'name': 'Samantha'}]
(Pdb) c
--Return--
> <ipython-input-27-551fea013d11>(15)<module>()->None
-> import pdb; pdb.set_trace()
(Pdb) c
Finished

Using pdb

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']
print("About to loop through some artists")
for artist in unpopular_artists:
    print("Looking at an artist named", artist['name'])
    display_artist_image(artist)
print("Done looping through artists")
About to loop through some artists
Looking at an artist named Lil Chuuuch
Inside of display_artist_image

jpeg

Looking at an artist named Lil Chewy
Inside of display_artist_image
Looking at an artist named Lil Kees
Inside of display_artist_image

jpeg

Looking at an artist named Lil Chaz
Inside of display_artist_image

jpeg

Looking at an artist named Lil Ruc
Inside of display_artist_image
Looking at an artist named Lil Base
Inside of display_artist_image
Looking at an artist named Lil David
Inside of display_artist_image

jpeg

Looking at an artist named Lil Nitty
Inside of display_artist_image
Looking at an artist named Lil Kmac
Inside of display_artist_image
Looking at an artist named Lil Woody
Inside of display_artist_image
Looking at an artist named Lil Tyreke
Inside of display_artist_image

jpeg

Looking at an artist named Lil Muggsy
Inside of display_artist_image
Looking at an artist named Lil Mbone
Inside of display_artist_image
Looking at an artist named Lil Nardy
Inside of display_artist_image

jpeg

Looking at an artist named Lil Tahj
Inside of display_artist_image

jpeg

Looking at an artist named Lil Chan
Inside of display_artist_image
Looking at an artist named Lil Cone
Inside of display_artist_image
Looking at an artist named Lil Dramma
Inside of display_artist_image
Looking at an artist named Lil Scott
Inside of display_artist_image

jpeg

Looking at an artist named Lil Ree
Inside of display_artist_image
Done looping through artists
# type any variable to see what its value is
# dir() - shows variables
# continue - continues on
# quit - shuts down whatever is going on, stops everything