list comprehension on export
This commit is contained in:
parent
d4b39fe9f2
commit
0726e15c9d
@ -1,21 +1,18 @@
|
|||||||
import csv
|
import csv
|
||||||
import spotframework.net.network as network
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
headers = ['name', 'artist', 'album', 'album artist', 'added', 'track id', 'album id', 'added by']
|
headers = ['name', 'artist', 'album', 'album artist', 'added', 'track id', 'album id', 'added by']
|
||||||
|
|
||||||
def exportPlaylist(playlist, path, name=None):
|
def exportPlaylist(playlist, path, name=None):
|
||||||
|
|
||||||
#playlist = network.getPlaylistTracks(user, playlistid)
|
|
||||||
|
|
||||||
date = str(datetime.datetime.now())
|
date = str(datetime.datetime.now())
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
name = playlist.name
|
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 = csv.DictWriter(fileobj, fieldnames=headers)
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
|
|
||||||
for track in playlist.tracks:
|
for track in playlist.tracks:
|
||||||
@ -27,17 +24,9 @@ def exportPlaylist(playlist, path, name=None):
|
|||||||
'track id':track['track']['id'],
|
'track id':track['track']['id'],
|
||||||
'album id':track['track']['album']['id'],
|
'album id':track['track']['album']['id'],
|
||||||
'added by':track['added_by']['id']}
|
'added by':track['added_by']['id']}
|
||||||
|
|
||||||
alart = []
|
|
||||||
for albumartist in track['track']['album']['artists']:
|
|
||||||
alart.append(albumartist['name'])
|
|
||||||
|
|
||||||
trackdict['album artist'] = ', '.join(alart)
|
trackdict['album artist'] = ', '.join(x['name'] for x in track['track']['album']['artists'])
|
||||||
|
|
||||||
art = []
|
trackdict['artist'] = ', '.join(x['name'] for x in track['track']['artists'])
|
||||||
for artist in track['track']['artists']:
|
|
||||||
art.append(artist['name'])
|
|
||||||
|
|
||||||
trackdict['artist'] = ', '.join(art)
|
|
||||||
|
|
||||||
writer.writerow(trackdict)
|
writer.writerow(trackdict)
|
||||||
|
@ -24,7 +24,7 @@ class network:
|
|||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
def getPlaylists(self, offset=0):
|
def getPlaylists(self, offset=0):
|
||||||
print('getting user playlists')
|
print('getting user playlists {}'.format(offset))
|
||||||
|
|
||||||
headers = {'Authorization': 'Bearer ' + self.user.access_token}
|
headers = {'Authorization': 'Bearer ' + self.user.access_token}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user