reworking to run from main

This commit is contained in:
Xevion
2019-10-27 16:52:20 -05:00
parent 48798de547
commit 9108ce3259
4 changed files with 22 additions and 15 deletions

View File

@@ -23,11 +23,13 @@ def main():
sp = spotipy.Spotify(auth=token)
logging.info('Authorized with Spotify via Spotipy')
tracks_folder = os.path.join(sys.path[0], 'tracks')
logging.warning('Clearing all files in tracks folder for new files')
shutil.rmtree(os.path.join(sys.path[0], 'tracks'))
if os.path.exists(tracks_folder):
shutil.rmtree(tracks_folder) # Delete folder and all contents (old track files)
os.path.makedirs(tracks_folder) # Recreate the folder just deleted
logging.info('Cleared folder, ready to download new track files')
root = sys.path[0]
curoffset, curlimit = 0, 50
while curoffset >= 0:
logging.info('Requesting tracks {} to {}'.format(curoffset, curoffset + curlimit))
@@ -35,7 +37,7 @@ def main():
received = len(response['items'])
logging.info('Received tracks {} to {}'.format(curoffset, curoffset + received))
filename = f'saved-tracks-{curoffset}-{curoffset + received}.json'
filepath = os.path.join(root, 'tracks', filename)
filepath = os.path.join(tracks_folder, filename)
with open(filepath, 'w+') as file:
json.dump(response, file)
logging.info('Saved at "{}" ({}KB)'.format(f'\\tracks\\{filename}', round(os.path.getsize(filepath) / 1024, 2)))