Added show_tracks example

This commit is contained in:
Paul Lamere
2014-07-03 06:36:36 -04:00
parent 803e338366
commit 4f6aef7e79
3 changed files with 26 additions and 1 deletions

24
examples/show_tracks.py Normal file
View File

@@ -0,0 +1,24 @@
'''
usage: show_tracks.py path_of_ids
given a list of track IDs show the artist and track name
'''
import sys
import spotipy
if __name__ == '__main__':
max_tracks_per_call = 50
if len(sys.argv) > 1:
file = open(sys.argv[1])
else:
file = sys.stdin
tids = file.read().split()
sp = spotipy.Spotify()
for start in xrange(0, len(tids), max_tracks_per_call):
results = sp.tracks(tids[start: start + max_tracks_per_call])
for track in results['tracks']:
print track['name'] + ' - ' + track['artists'][0]['name']