Created
April 7, 2016 06:39
-
-
Save avyfain/e939e00380bcbc3d6724c96585108a6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Radiohead | |
LCD Soundsystem | |
Lionel Richie | |
Lana Del Rey | |
J. Cole | |
Duran Duran | |
Zedd | |
Ryan Adams | |
Major Lazer | |
Air | |
Sufjan Stevens | |
Chance The Rapper | |
Beach House | |
Miguel | |
Halsey | |
Big Grams | |
Grimes | |
Jason Isbell | |
Miike Snow | |
Third Eye Blind | |
Kehlani | |
The Last Shadow Puppets | |
Griz | |
Brandi Carlile | |
Thomas Jack | |
Nathaniel Rateliff & The Night Sweats | |
Foals | |
Lord Huron | |
Jauz | |
The Claypool Lennon Delirium | |
St. Lucia | |
Years & Years | |
Vince Staples | |
Poliça | |
Lettuce | |
Ibeyi | |
Hiatus Kaiyote | |
Peaches | |
Anderson .Paak & The Free Nationals | |
Snakehips | |
Oh Wonder | |
Kamasi Washington | |
Jack Garratt | |
Rüfüs Du Sol | |
Ra Ra Riot Tokimonsta | |
The Knocks | |
Wet | |
Jidenna | |
Diiv | |
Natalia Lafourcade | |
Låpsley | |
The Wombats | |
Rogue Wave | |
The Oh Hellos | |
Marian Hill | |
Con Brio | |
Kevin Morby | |
Caveman | |
Fantastic Negrito | |
Frances | |
Lewis Del Mar | |
Vulfpeck | |
Moon Taxi | |
Julien Baker | |
Lany | |
Hælos | |
Declan Mckenna | |
Cloves | |
Heron Oblivion | |
Whitney | |
Methyl Ethel | |
Dr. Teeth And The Electric Mayhem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check out the playlist here! | |
# https://open.spotify.com/user/avyfain/playlist/2L9B4CsI1J6cX6GMv4AJQf | |
# export SPOTIPY_CLIENT_ID='SPOTIPY_CLIENT_ID_GOES_HERE' | |
# export SPOTIPY_CLIENT_SECRET='SPOTIPY_CLIENT_SECRET_GOES_HERE' | |
# export SPOTIPY_REDIRECT_URI='SPOTIPY_REDIRECT_URI_GOES_HERE' | |
import spotipy | |
import spotipy.util as spu | |
import json | |
scope = 'playlist-modify-private' | |
# token = spu.prompt_for_user_token('USER', scope) | |
token = 'TOKEN HERE' | |
sp = spotipy.Spotify(auth=token) | |
def find_artist_by_name(name): | |
results = sp.search(q='artist:' + name, type='artist') | |
artists = results['artists']['items'] | |
try: | |
most_pop = max(artists, key=lambda art: art['popularity']) | |
print(most_pop['name']) | |
return most_pop | |
except ValueError: | |
print("Couldn't find artist with name %s", name) | |
def find_top_tracks_for_artist(artist): | |
if artist is None: | |
return [] | |
results = sp.artist_top_tracks(artist['uri']) | |
tracks = results['tracks'] | |
return tracks | |
def main(): | |
with open('artists.txt') as f: | |
for name in f: | |
artist = find_artist_by_name(name) | |
artist_track_ids = [] | |
for track in find_top_tracks_for_artist(artist): | |
print(track['name']) | |
artist_track_ids.append(track['id']) | |
if artist_track_ids: | |
sp.user_playlist_add_tracks("avyfain", "PLAYLIST ID HERE", artist_track_ids) | |
print() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment