-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotipyFuncs.py
31 lines (24 loc) · 992 Bytes
/
spotipyFuncs.py
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
import os
from json.decoder import JSONDecodeError
import spotipy.util as util
import spotipy
def get_token(username, scope='', loc='keys.py'):
from keys import client_id, client_secret
""" Get spotipy access token with specified scope and keys"""
redirect_uri = 'http://localhost/'
try:
token = util.prompt_for_user_token(username, scope, client_id,
client_secret, redirect_uri)
except (AttributeError, JSONDecodeError):
os.remove(f".cache-{username}")
token = util.prompt_for_user_token(username, scope, client_id,
client_secret, redirect_uri)
return token
def spotify_login():
"""Function to loginto hrkp's spotipy"""
# Get access token
token = get_token('hrkp',
scope='user-modify-playback-state playlist-read-private\
user-modify-private')
sp = spotipy.Spotify(auth=token)
return sp