From ad1c0995b1db1ffbcdedf6389594ba4a491dfe73 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 27 Oct 2019 13:36:56 -0500 Subject: [PATCH] pull.py abstraction --- pull.py | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/pull.py b/pull.py index d0ee8d7..479e472 100644 --- a/pull.py +++ b/pull.py @@ -4,22 +4,31 @@ import pprint import spotipy import spotipy.util as util -# Get Authorization -token = util.prompt_for_user_token( - username=auth.username, - scope=auth.scope, - client_id=auth.client_id, - client_secret=auth.client_secret, - redirect_uri=auth.redirect_uri -) -sp = spotipy.Spotify(auth=token) -saved_response = sp.current_user_saved_tracks(limit=50, offset=100000) -# saved_response = json.load(open('saved_tracks.json', 'r')) -json.dump(saved_response, open('saved_tracks.json', 'w+')) -pprint.pprint(saved_response) -# for track in saved_response['items']: -# print('{} by {}'.format( -# track['track']['name'], -# ' & '.join(artist['name'] for artist in track['track']['artists']) -# )) +def main(): + # Get Authorization + print('Authorizing with Spotify') + token = util.prompt_for_user_token( + username=auth.username, + scope=auth.scope, + client_id=auth.client_id, + client_secret=auth.client_secret, + redirect_uri=auth.redirect_uri + ) + sp = spotipy.Spotify(auth=token) + print('Authorized') + curoffset = 0 + curlimit = 50 + while True: + + # Start grabbing tracks (long running) + saved_response = sp.current_user_saved_tracks(limit=50, offset=850) + # saved_response = json.load(open('saved_tracks.json', 'r')) + # json.dump(saved_response, open('saved_tracks.json', 'w+')) + pprint.pprint(saved_response) + + # for track in saved_response['items']: + # print('{} by {}'.format( + # track['track']['name'], + # ' & '.join(artist['name'] for artist in track['track']['artists']) + # )) \ No newline at end of file