2019-09-04 17:45:26 +01:00
|
|
|
from spotframework.net.user import NetworkUser
|
2019-06-11 11:59:24 +01:00
|
|
|
from spotframework.net.network import Network
|
2019-02-28 07:49:52 +00:00
|
|
|
import spotframework.io.csv as csvwrite
|
|
|
|
|
2019-05-14 12:39:17 +01:00
|
|
|
import sys
|
|
|
|
import datetime
|
|
|
|
import os
|
2019-08-07 15:45:25 +01:00
|
|
|
import logging
|
2019-03-04 21:31:32 +00:00
|
|
|
|
2019-02-28 07:49:52 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2019-08-07 15:45:25 +01:00
|
|
|
logger = logging.getLogger('spotframework')
|
|
|
|
|
|
|
|
log_format = '%(asctime)s %(levelname)s %(name)s:%(funcName)s - %(message)s'
|
|
|
|
|
|
|
|
file_handler = logging.FileHandler(".spot/backup.log")
|
|
|
|
formatter = logging.Formatter(log_format)
|
|
|
|
file_handler.setFormatter(formatter)
|
|
|
|
|
|
|
|
logger.addHandler(file_handler)
|
|
|
|
|
2019-09-05 12:20:21 +01:00
|
|
|
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
|
|
|
|
stream_formatter = logging.Formatter(stream_log_format)
|
|
|
|
|
|
|
|
stream_handler = logging.StreamHandler()
|
|
|
|
stream_handler.setFormatter(stream_formatter)
|
|
|
|
|
|
|
|
logger.addHandler(stream_handler)
|
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
try:
|
2019-05-08 22:41:47 +01:00
|
|
|
|
2019-09-04 17:45:26 +01:00
|
|
|
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
|
|
|
os.environ['SPOTSECRET'],
|
|
|
|
os.environ['SPOTREFRESH']))
|
2019-06-11 11:59:24 +01:00
|
|
|
playlists = network.get_user_playlists()
|
2019-03-04 22:45:58 +00:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
for playlist in playlists:
|
2019-09-15 15:33:29 +01:00
|
|
|
playlist.tracks = network.get_playlist_tracks(playlist.uri)
|
2019-02-28 07:49:52 +00:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
path = sys.argv[1]
|
2019-05-14 12:39:17 +01:00
|
|
|
|
2019-05-14 13:05:25 +01:00
|
|
|
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:
|
2019-06-11 11:59:24 +01:00
|
|
|
csvwrite.export_playlist(play, totalpath)
|
2019-05-14 13:05:25 +01:00
|
|
|
|
2019-08-07 15:45:25 +01:00
|
|
|
except Exception as e:
|
|
|
|
logger.exception(f'exception occured')
|