mirror of
https://github.com/c0de-archive/spotipy-experiments.git
synced 2024-12-22 01:32:40 +00:00
Get a user's top 20 tracks and save it to a json file
This commit is contained in:
parent
b15da78df1
commit
95e34d0b0a
27
top_tracks.py
Normal file
27
top_tracks.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user