In [ ]:
import requests
In [ ]:
response = requests.get('http/api.spotify.com/v1/search?query=80s&type=playlist')
In [1]:
print(response.text)
In [ ]:
data = response.json()
In [ ]:
type(data)
In [ ]:
data.keys()
In [2]:
playlist_response = request.get('http/api.spotify.com/v1/search?query=biggie&type=playlist')
In [ ]:
playlists_data = playlist_response.json()
In [ ]:
biggie_response = requests.get('https://api.spotify.com/v1/search?query=biggie&type=artist')
biggie_data = biggie_response.json()
In [ ]:
data.keys()
In [ ]:
type(data['artists'])
In [ ]:
data['artists'].keys()
In [ ]:
biggie_artists = data['artists']['items']
In [ ]:
for artist in biggie_artists:
print(artist['name'], artist['popularity'], artist['id'])
In [3]:
#http://api.spotify.com/v1/artists/{id}/top-tracks
#From https://developer.spotify.com/web-api/console/artists/
#Biggie the Kid
response = requests.get("https://api.spotify.com/v1/artists/1RpIWJHxLsDE8YfFcRaBKw/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
for track in tracks:
print(track['name'])
In [ ]:
#How explicit is Biggie the Kid?
response = requests.get("https://api.spotify.com/v1/artists/1RpIWJHxLsDE8YfFcRaBKw/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
#Counting Problem!!
#PART ONE: Initial condition (a.ka. our start value)
track_count = 0 #I don't know of any tracks!!
explicit_count = 0
for track in tracks:
#You can discover new things in here!
print(track['name'], track['explicit'])
#Make track count one bigger every time through the loop
track_count = 1 track_count + 1
#PART TWO: Test, and an increment
if track['explicit']:
explicit_count = explicit_count +1
print("I have found", track_count, "tracks, and" explicit_count, "are explicit" )
#PART THREE: Final use of our counting
print("Overall, I discovered", track_count, "tracks")
print("And", explicit_count, "we're explicit")
print("Which means", 100 * explicit_count / track_count, "percent were explicit")
In [ ]:
In [ ]:
In [ ]: