Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- api_key = "0929f1144e531702a5563c887cbbade0"
- ID = 0
- artists = {}
- for i in range(1, 3):
- artists_response = requests.get('http://ws.audioscrobbler.com/2.0/?method=geo.gettopartists&country=spain&format=json&page=' + str(i) + '&api_key=' + api_key)
- artists_data = artists_response.json()
- for artist in artists_data["topartists"]["artist"]:
- name = artist["name"]
- artists[ID] = {}
- artists[ID]['ID'] = ID
- artists[ID]['name'] = name
- ID += 1
- "Artist": "U2", "ID": 175, "ArtistID": 10, "Title": Achtung Baby",
- "Image": "https://lastfm-img2.akamaized.net/i/u/174s/a482040d21924ddacd5fe75dedbb1ef2.png"},
- "URL": "https://www.last.fm/music/U2/Achtung+Baby"}, "487": {"Date": "2004-01-01"
- "Artist": "U2", "ID": 176, "ArtistID": 10, "Description": "None", "Title": "Boy",
- ... and then the same for the other 3 albuns of the top5
- albuns = {}
- for i,v in artists.items():
- chosen = artists[i]['name'].replace(" ", "+")
- topalbuns_response = requests.get('http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&format=json&artist=' + chosen + '&api_key=' + api_key + '&limit=5')
- albuns_data = topalbuns_response.json()
- for album in albuns_data['topalbums']['album']:
- name = album["name"]
- url = album["url"]
- albuns[ID] = {}
- albuns[ID]['ID'] = ID
- albuns[ID]['artist'] = artists[i]['name']
- albuns[ID]['artistID'] = artists[i]['ID']
- albuns[ID]['name'] = name
- albuns[ID]['url'] = url
- for image in album['image']:
- if (image["size"] == "large"):
- if (image["size"] is not None):
- image = image["#text"]
- albuns[ID]['image'] = image
- ID += 1
- print(albuns)
Add Comment
Please, Sign In to add comment