Skip to content

Instantly share code, notes, and snippets.

@djmango
Last active April 9, 2021 18:00
Show Gist options
  • Save djmango/82f0898ac91285d7fd106ab3e338aeeb to your computer and use it in GitHub Desktop.
Save djmango/82f0898ac91285d7fd106ab3e338aeeb to your computer and use it in GitHub Desktop.
Automatically gives you all your artist crowns for the Discord last.fm fmbot
""" just a little script to automatically type out messages per artist you follow on spotify, very specific use case but automation is fun """
from time import sleep
import pyautogui
import spotipy
import spotipy.util as util
SPOTIPY_CLIENT_ID = 'YOUR_APP_ID'
SPOTIPY_CLIENT_SECRET = 'YOUR_APP_SECRET'
USERNAME = 'YOUR_USERNAME'
scope = 'user-follow-read'
token = util.prompt_for_user_token(USERNAME, scope, client_id=SPOTIPY_CLIENT_ID,
client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri='https://github.com/djmango')
def get_all_artists(after=None):
artists = []
finished = False
while not finished:
# get the next 50
if after is None:
artistRequest = sp.current_user_followed_artists(limit=50)['artists']
else:
artistRequest = sp.current_user_followed_artists(limit=50, after=after)['artists']
for artist in artistRequest['items']:
artists.append((artist['name'], artist['id']))
if len(artistRequest['items']) < 50:
finished = True
return artists
else:
after = artists[len(artists)-1][1]
else:
print('No followed artists found!')
# make sure we auth'd
if token:
sp = spotipy.Spotify(auth=token)
# get all artists
artists = get_all_artists()
print(f'got {len(artists)} artists')
print('typing in 2 secs..')
sleep(2)
# type them out in the bot format
for artist in artists:
pyautogui.typewrite(f'.fmwk {artist[0]}\n')
else:
print("Can't get token for", USERNAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment