Created
March 10, 2017 04:28
-
-
Save alairock/845547078e8dac8df90d9fb1199cda5d to your computer and use it in GitHub Desktop.
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 requests | |
import sys | |
import urllib | |
from pprint import pprint | |
url = "http://ws.audioscrobbler.com/2.0/" | |
body = { | |
'method': "user.gettopartists", | |
'user': "alairock", | |
'api_key': '301a3a6d4301644d5a078e7f1fac0e78', | |
'limit': 9, | |
'period': '3month', | |
'format': 'json' | |
} | |
r = requests.get(url, body) | |
if r.status_code == 403: | |
print('cannot access') | |
sys.exit() | |
artists = r.json()['topartists']['artist'] | |
def download_file(url, directory): | |
path = directory + "/" + 'newfile.jpg' | |
print(path) | |
urllib.request.urlretrieve(url , path) # <-- This works now! | |
for artist in artists: | |
url = artist['image'][3]['#text'] | |
download_file(url, '/Users/alairock/Desktop') | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment