mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-06 14:52:50 +00:00
Added top artists and tracks support
This commit is contained in:
parent
4587a0771d
commit
4cf7a8ab90
30
examples/my_top_artists.py
Normal file
30
examples/my_top_artists.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Shows the top artists for a user
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import spotipy
|
||||||
|
import spotipy.util as util
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
username = sys.argv[1]
|
||||||
|
else:
|
||||||
|
print("Usage: %s username" % (sys.argv[0],))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
scope = 'user-top-read'
|
||||||
|
token = util.prompt_for_user_token(username, scope)
|
||||||
|
|
||||||
|
if token:
|
||||||
|
sp = spotipy.Spotify(auth=token)
|
||||||
|
sp.trace = False
|
||||||
|
ranges = ['short_term', 'medium_term', 'long_term']
|
||||||
|
for range in ranges:
|
||||||
|
print "range:", range
|
||||||
|
results = sp.current_user_top_artists(time_range=range, limit=50)
|
||||||
|
for i, item in enumerate(results['items']):
|
||||||
|
print i, item['name']
|
||||||
|
print
|
||||||
|
else:
|
||||||
|
print("Can't get token for", username)
|
31
examples/my_top_tracks.py
Normal file
31
examples/my_top_tracks.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Adds tracks to a playlist
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import spotipy
|
||||||
|
import spotipy.util as util
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
username = sys.argv[1]
|
||||||
|
else:
|
||||||
|
print("Usage: %s username" % (sys.argv[0],))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
scope = 'user-top-read'
|
||||||
|
token = util.prompt_for_user_token(username, scope)
|
||||||
|
|
||||||
|
if token:
|
||||||
|
sp = spotipy.Spotify(auth=token)
|
||||||
|
sp.trace = False
|
||||||
|
ranges = ['short_term', 'medium_term', 'long_term']
|
||||||
|
for range in ranges:
|
||||||
|
print "range:", range
|
||||||
|
results = sp.current_user_top_tracks(time_range=range, limit=50)
|
||||||
|
for i, item in enumerate(results['items']):
|
||||||
|
print i, item['name'], '//', item['artists'][0]['name']
|
||||||
|
print
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Can't get token for", username)
|
Loading…
Reference in New Issue
Block a user