adding date folder generation

This commit is contained in:
aj 2019-03-04 22:45:58 +00:00
parent afc73bb8e1
commit 804b0b607e
2 changed files with 14 additions and 3 deletions

View File

@ -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')

View File

@ -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()