list comprehension on export
This commit is contained in:
parent
d4b39fe9f2
commit
0726e15c9d
@ -1,19 +1,16 @@
|
||||
import csv
|
||||
import spotframework.net.network as network
|
||||
import datetime
|
||||
|
||||
headers = ['name', 'artist', 'album', 'album artist', 'added', 'track id', 'album id', 'added by']
|
||||
|
||||
def exportPlaylist(playlist, path, name=None):
|
||||
|
||||
#playlist = network.getPlaylistTracks(user, playlistid)
|
||||
|
||||
date = str(datetime.datetime.now())
|
||||
|
||||
if name is None:
|
||||
name = playlist.name
|
||||
|
||||
with open('{}/{}_{}.csv'.format(path, name.replace('/', '_'), date.split('.')[0]), 'w') as fileobj:
|
||||
with open('{}/{}_{}.csv'.format(path, name.replace('/', '_'), date.split('.')[0]), 'w', newline='') as fileobj:
|
||||
|
||||
writer = csv.DictWriter(fileobj, fieldnames=headers)
|
||||
writer.writeheader()
|
||||
@ -28,16 +25,8 @@ def exportPlaylist(playlist, path, name=None):
|
||||
'album id':track['track']['album']['id'],
|
||||
'added by':track['added_by']['id']}
|
||||
|
||||
alart = []
|
||||
for albumartist in track['track']['album']['artists']:
|
||||
alart.append(albumartist['name'])
|
||||
trackdict['album artist'] = ', '.join(x['name'] for x in track['track']['album']['artists'])
|
||||
|
||||
trackdict['album artist'] = ', '.join(alart)
|
||||
|
||||
art = []
|
||||
for artist in track['track']['artists']:
|
||||
art.append(artist['name'])
|
||||
|
||||
trackdict['artist'] = ', '.join(art)
|
||||
trackdict['artist'] = ', '.join(x['name'] for x in track['track']['artists'])
|
||||
|
||||
writer.writerow(trackdict)
|
||||
|
@ -24,7 +24,7 @@ class network:
|
||||
return playlist
|
||||
|
||||
def getPlaylists(self, offset=0):
|
||||
print('getting user playlists')
|
||||
print('getting user playlists {}'.format(offset))
|
||||
|
||||
headers = {'Authorization': 'Bearer ' + self.user.access_token}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user