Код: Выделить всё
def setup():
spOauth = SpotifyOAuth(client_id=CLIENTID,
client_secret=CLIENTSECRET,
redirect_uri=REDIRECTURI,
scope=SCOPE,
show_dialog=True)
return Spotify(auth_manager = spOauth)
def main():
anon = "insert anon here"
url = "insert supabase url here"
supabase: Client = create_client(url,anon) #set up the connection to the database
sp = setup() #set up the connection to spotipy
refreshRate = 30
current = {"length": 120000} #default used for if no song is being listened to
run = True
count = -1
while run:
nowp = getCurrentSong(sp)
if nowp == 0:
sp = setup()
else:
if nowp != current:
if count >=current["length"]/2000: #if youve listened to half the song add
SQLappend(current,supabase)
if nowp!=-1: #if there is a new song
current = nowp #update current
refreshRate = current["length"]/4000 # and refreshrate
else:
current = {"length": 120000} # if the music has stopped go back to default
refreshRate = current["length"]/4000
count = 0 #reset timer
elif nowp != -1: #if there is music
count = count+refreshRate #keep track of for how long
time.sleep(refreshRate)#wait some amount of time
Подробнее здесь: https://stackoverflow.com/questions/797 ... onanywhere