mirror of
https://github.com/JonasunderscoreJones/turbo-octo-potato.git
synced 2025-10-28 03:29:18 +01:00
Refactor to obey to pep-8
This commit is contained in:
parent
9f3692c217
commit
42a6e153fa
1 changed files with 14 additions and 12 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
import spotipy, os
|
'''Get the last spotify track'''
|
||||||
from spotipy.oauth2 import SpotifyOAuth
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
import top_lib
|
||||||
|
|
||||||
# load .env file
|
# load .env file
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
|
@ -11,24 +13,24 @@ SPOTIFY_CLIENT_SECRET = os.getenv('SPOTIFY_CLIENT_SECRET')
|
||||||
SPOTIFY_REDIRECT_URI = os.getenv('SPOTIFY_REDIRECT_URI')
|
SPOTIFY_REDIRECT_URI = os.getenv('SPOTIFY_REDIRECT_URI')
|
||||||
PLAYLIST_ID = os.getenv('SOMEPLAYLIST_ID')
|
PLAYLIST_ID = os.getenv('SOMEPLAYLIST_ID')
|
||||||
|
|
||||||
if not SPOTIFY_CLIENT_ID or not SPOTIFY_CLIENT_SECRET or not SPOTIFY_REDIRECT_URI or not PLAYLIST_ID:
|
if not SPOTIFY_CLIENT_ID or not SPOTIFY_CLIENT_SECRET or \
|
||||||
raise ValueError("Please provide the required information in the .env file.")
|
not SPOTIFY_REDIRECT_URI or not PLAYLIST_ID:
|
||||||
|
raise ValueError("Please provide the required information in the .env file.")
|
||||||
|
|
||||||
# Create a Spotipy instance with authentication
|
# Create a Spotipy instance with authentication
|
||||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=SPOTIFY_CLIENT_ID, client_secret=SPOTIFY_CLIENT_SECRET, redirect_uri=SPOTIFY_REDIRECT_URI, scope="playlist-read-private"))
|
auth_manager = top_lib.Auth(verbose=True)
|
||||||
|
sp = auth_manager.newSpotifyauth("playlist-read-private")
|
||||||
|
|
||||||
def get_last_track_of_playlist(playlist_id):
|
def get_last_track_of_playlist(playlist_id: str) -> dict:
|
||||||
|
'''Get the last track of a playlist'''
|
||||||
# Get the playlist's tracks
|
# Get the playlist's tracks
|
||||||
playlist = sp.playlist_tracks(playlist_id)
|
playlist = sp.playlist_tracks(playlist_id)
|
||||||
|
|
||||||
# Extract the last track
|
# Extract the last track
|
||||||
last_track = playlist["items"][-1]["track"]
|
return playlist["items"][-1]["track"]
|
||||||
|
|
||||||
return last_track
|
# Retrieve the last track of the playlist
|
||||||
|
last_track = get_last_track_of_playlist(PLAYLIST_ID)
|
||||||
# Replace "YOUR_PLAYLIST_ID" with the actual playlist ID
|
|
||||||
playlist_id = PLAYLIST_ID
|
|
||||||
last_track = get_last_track_of_playlist(playlist_id)
|
|
||||||
|
|
||||||
# Access information about the last track
|
# Access information about the last track
|
||||||
print("Last Track Name:", last_track["name"])
|
print("Last Track Name:", last_track["name"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue