Get a user's top 20 tracks and save it to a json file

This commit is contained in:
David Todd 2018-04-24 20:47:14 -05:00
parent b15da78df1
commit 95e34d0b0a
1 changed files with 27 additions and 0 deletions

27
top_tracks.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
# Writes the now playing track to a text file
# License: MIT
# Copyright (c) 2018 c0de <c0defox.es>
import sys
import time
import json
import spotipy
import spotipy.util as util
if len(sys.argv) > 2:
username = sys.argv[1]
outfile = sys.argv[2]
else:
print "Usage: %s username outfile" % sys.argv[0]
sys.exit()
# Authorization Scope, can possibly be a dict?
scope = 'user-top-read'
sp = util.authorize_api(username, scope, 'server')
tt = json.dumps(sp.current_user_top_tracks())
with open(outfile+'.json', 'w') as output:
output.write(tt)
output.close()