From 08ccf64e5ec620e10c429695aab93616344573a3 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 27 Oct 2019 13:42:37 -0500 Subject: [PATCH] file saving additionsn --- process.py | 8 ++++++++ pull.py | 26 ++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 process.py diff --git a/process.py b/process.py new file mode 100644 index 0000000..148ac16 --- /dev/null +++ b/process.py @@ -0,0 +1,8 @@ +import json + + saved_response = json.load(open('saved_tracks.json', 'r')) + 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 diff --git a/pull.py b/pull.py index 479e472..ba78504 100644 --- a/pull.py +++ b/pull.py @@ -1,3 +1,5 @@ +import os +import sys import auth import json import pprint @@ -17,18 +19,14 @@ def main(): sp = spotipy.Spotify(auth=token) print('Authorized') - curoffset = 0 - curlimit = 50 - while True: - + curoffset, curlimit = 0, 50 # 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 + while True: + response = sp.current_user_saved_tracks(limit=curlimit, offset=curoffset) + if response is not None: + print('Received ') + filename = f'saved-tracks-{curoffset}-{curoffset + curlimit}.json' + filepath = os.path.join(root, 'tracks', filename) + with open(filepath, 'w+') as file: + json.dump(response, file) + curoffset += curlimit