-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
init.py
30 lines (24 loc) · 836 Bytes
/
init.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
"""Spotisub init script"""
import os
from os.path import dirname
from os.path import join
from dotenv import load_dotenv
import spotipy
from spotipy import SpotifyOAuth
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
client_id = os.environ.get("SPOTIPY_CLIENT_ID")
client_secret = os.environ.get("SPOTIPY_CLIENT_SECRET")
redirect_uri = os.environ.get("SPOTIPY_REDIRECT_URI")
SCOPE = "user-top-read,user-library-read,user-read-recently-played"
creds = SpotifyOAuth(
scope=SCOPE,
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
open_browser=False,
cache_path=os.path.dirname(
os.path.abspath(__file__)) +
"/cache/spotipy_cache")
sp = spotipy.Spotify(auth_manager=creds)
top_tracks = sp.current_user_top_tracks(limit=50, time_range='long_term')