added path specification for export and user playlists only

This commit is contained in:
aj 2019-03-04 21:31:32 +00:00
parent 447f68a893
commit 45de569308
4 changed files with 10 additions and 9 deletions

View File

@ -2,11 +2,14 @@ import spotframework.net.user as userclass
import spotframework.net.playlist as playlist import spotframework.net.playlist as playlist
import spotframework.io.csv as csvwrite import spotframework.io.csv as csvwrite
import sys
if __name__ == '__main__': if __name__ == '__main__':
user = userclass.User() user = userclass.User()
playlists = playlist.getPlaylists(user) playlists = playlist.getUserPlaylists(user)
for play in playlists: for play in playlists:
csvwrite.exportPlaylist(user, play['id'], play['name']) csvwrite.exportPlaylist(user, play['id'], play['name'], sys.argv[1])
print(play['name'] + ' exported')

View File

@ -27,6 +27,6 @@ if __name__ == '__main__':
import spotframework.io.csv as csvwrite import spotframework.io.csv as csvwrite
csvwrite.exportPlaylist(user, '000Eh2vXzYGgrEFlgcWZj3', 'february') csvwrite.exportPlaylist(user, '000Eh2vXzYGgrEFlgcWZj3', 'february', '')
print(user.access_token) print(user.access_token)

View File

@ -4,11 +4,11 @@ import datetime
headers = ['name', 'artist', 'album', 'album artist', 'added', 'spotify id', 'added by'] headers = ['name', 'artist', 'album', 'album artist', 'added', 'spotify id', 'added by']
def exportPlaylist(user, playlistid, name): def exportPlaylist(user, playlistid, name, path):
playlist = playlistpull.getPlaylistTracks(user, playlistid) playlist = playlistpull.getPlaylistTracks(user, playlistid)
with open('{}_{}.csv'.format(name, str(datetime.datetime.now()).split('.')[0]), 'w') as fileobj: with open('{}{}_{}.csv'.format(path, name.replace('/', '_'), str(datetime.datetime.now()).split('.')[0]), 'w') as fileobj:
writer = csv.DictWriter(fileobj, fieldnames = headers) writer = csv.DictWriter(fileobj, fieldnames = headers)
writer.writeheader() writer.writeheader()

View File

@ -57,7 +57,7 @@ def getPlaylistTracks(user, playlistid, offset = 0):
if req.status_code == 200: if req.status_code == 200:
print(req.text) #print(req.text)
resp = req.json() resp = req.json()
tracks += resp['items'] tracks += resp['items']
@ -70,6 +70,4 @@ def getPlaylistTracks(user, playlistid, offset = 0):
return tracks return tracks
else: else:
return None raise ValueError("Couldn't Pull Playlist " + str(playlistid) + ' ' + str(req.status_code))