diff --git a/backup.py b/backup.py index 18e2e0e..1c638d9 100644 --- a/backup.py +++ b/backup.py @@ -2,14 +2,23 @@ import spotframework.net.user as userclass import spotframework.net.playlist as playlist import spotframework.io.csv as csvwrite -import sys +import sys, datetime, os if __name__ == '__main__': user = userclass.User() playlists = playlist.getUserPlaylists(user) + + path = sys.argv[1] + + datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/') + + totalpath = os.path.join(path, datepath) + pathdir = os.path.dirname(totalpath) + if not os.path.exists(totalpath): + os.makedirs(totalpath) for play in playlists: - csvwrite.exportPlaylist(user, play['id'], play['name'], sys.argv[1]) + csvwrite.exportPlaylist(user, play['id'], play['name'], totalpath) print(play['name'] + ' exported') diff --git a/spotframework/io/csv.py b/spotframework/io/csv.py index 93053a7..0d0ac5d 100644 --- a/spotframework/io/csv.py +++ b/spotframework/io/csv.py @@ -7,8 +7,10 @@ headers = ['name', 'artist', 'album', 'album artist', 'added', 'track id', 'albu def exportPlaylist(user, playlistid, name, path): playlist = playlistpull.getPlaylistTracks(user, playlistid) + + date = str(datetime.datetime.now()) - with open('{}{}_{}.csv'.format(path, name.replace('/', '_'), str(datetime.datetime.now()).split('.')[0]), 'w') as fileobj: + with open('{}/{}_{}.csv'.format(path, name.replace('/', '_'), date.split('.')[0]), 'w') as fileobj: writer = csv.DictWriter(fileobj, fieldnames = headers) writer.writeheader()