innovative
it updates whenever I listen to music
that is awesome (how do you do that)
import spotipy
import spotipy.util as util
import requests
import json
import time
client_id = 'redacted'
client_secret = 'redacted'
redirect_uri = 'http://localhost:8090/callback'
username = 'redacted'
scope = 'user-read-currently-playing'
token = util.prompt_for_user_token(username, scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
if token:
sp = spotipy.Spotify(auth=token)
while True:
# Get the user's currently playing track
track = sp.current_user_playing_track()
if track:
title = track['item']['name']
author = track['item']['artists'][0]['name']
else:
title = 'Not listening'
author = ''
data = {'title': title, 'author': author}
print(data)
currentbio = requests.get("https://api.wasteof.money/users/username/bio").json()["bio"]
currentbio = currentbio.split("")[0]
if title == "Not listening":
newbio = currentbio + " | Not listening to anything on Spotify"
else:
if author == "":
newbio = currentbio + f" | Listening to {title} on Spotify"
else:
newbio = currentbio + f" | Listening to {title} by {author} on Spotify"
setbio = requests.put("https://api.wasteof.money/users/username/bio", json = {"bio": newbio}, headers = {"Authorization": "redacted"})
print(setbio.json())
time.sleep(15)
else:
print("Can't get token for", username)