adding date folder generation
This commit is contained in:
parent
afc73bb8e1
commit
804b0b607e
13
backup.py
13
backup.py
@ -2,7 +2,7 @@ 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
|
import sys, datetime, os
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
@ -10,6 +10,15 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
playlists = playlist.getUserPlaylists(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:
|
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')
|
print(play['name'] + ' exported')
|
||||||
|
@ -8,7 +8,9 @@ def exportPlaylist(user, playlistid, name, path):
|
|||||||
|
|
||||||
playlist = playlistpull.getPlaylistTracks(user, playlistid)
|
playlist = playlistpull.getPlaylistTracks(user, playlistid)
|
||||||
|
|
||||||
with open('{}{}_{}.csv'.format(path, name.replace('/', '_'), str(datetime.datetime.now()).split('.')[0]), 'w') as fileobj:
|
date = str(datetime.datetime.now())
|
||||||
|
|
||||||
|
with open('{}/{}_{}.csv'.format(path, name.replace('/', '_'), date.split('.')[0]), 'w') as fileobj:
|
||||||
|
|
||||||
writer = csv.DictWriter(fileobj, fieldnames = headers)
|
writer = csv.DictWriter(fileobj, fieldnames = headers)
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
|
Loading…
Reference in New Issue
Block a user