-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (26 loc) · 1.06 KB
/
main.py
File metadata and controls
31 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from GetToken import GettingToken
from SpotipyAUTH import GetSpotipyAUTH
import json
import os
#You can use the method below as an alternative way to login.
#token = GettingToken()
#Here is the recommended way to login.
sp = GetSpotipyAUTH()
#You can set the artist ID in your .env file.
#Here's more information about the Spotify artist ID:
#https://developer.spotify.com/documentation/web-api/
artistID = os.getenv("ARTIST_ID")
Spotify_URI = 'spotify:artist:' + artistID
results = sp.artist_top_tracks(Spotify_URI)
print(json.dumps(results, indent=4, sort_keys=True))
#Print the top tracks of the artist along withe the audio, popularity, and cover art.
for track in results['tracks'][:10]:
print('track : ' + track['name'])
print('audio : ' + track['preview_url'])
print('popularity : ' + str(track['popularity']))
print('cover art: ' + track['album']['images'][0]['url'])
print("")
#Get the related artists.
Spotify_URI = 'spotify:artist:' + artistID
results = sp.artist_related_artists(Spotify_URI)
print(json.dumps(results, indent=4, sort_keys=True))