Forked from Brittt94/gist:d134814da299a90ec17a9dae7dc1228c
Last active
May 3, 2020 04:30
-
-
Save Sutto/453bb73e521dcb0af5db3994ccfe94ad to your computer and use it in GitHub Desktop.
Graded Exercise 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import pandas as pd | |
data = pd.read_csv('artists.csv',sep=';') # Reading data from csv | |
data = data.T.to_dict().values() # Converting dataframe into list of dictionaries | |
json_data = [] # Empty list to temporarily save the new data, and at the end write it into a new CSV | |
# Iterate through the imported data | |
for item in data: | |
print('Searching for',item['Artist']) | |
headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer BQCEh6JKyozS6x6TwXmgnjjUgn86TxScZadaIVnuo_pAdbC4sfxDQfZrJB4R9xU1VZvK8w_8KGCvtTv-bdx38E5p-bK6Ns1PvrU2mbCvw6GW-EhAi_B7DMKJYdTqedIrLiOoHDwcmVY', | |
} | |
params = ( | |
('q', item['Artist']), # Per iteration, the value of q = the read artist | |
('type', 'artist'), | |
) | |
response = requests.get('https://api.spotify.com/v1/search', headers=headers, params=params) # request the response | |
# The endpoint base url is supplemented by the arguments in the variables headers and params | |
current_json = json.loads(response.text) # convert json response to text/dict | |
json_data.append(current_json) | |
print(json_data) | |
# for item in json_data: | |
# print(item['artists']['items'][0]['images'][0]['url']) # Isolating the genre information - as a list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment