added slack notifying, playlist description writing

This commit is contained in:
aj 2019-05-26 20:42:01 +01:00
parent 81c2c290dd
commit 793b03c28d
3 changed files with 39 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import spotframework.net.user as user
import spotframework.log.log as log
import spotframework.io.json as json
import requests
import os
if __name__ == '__main__':
@ -36,6 +38,8 @@ if __name__ == '__main__':
else:
log.log("requested playlist {} not found".format(part))
if 'SLACKHOOK' in os.environ:
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: {} not found".format(part)})
if 'shuffle' in tomake:
if tomake['shuffle'] is True:
@ -47,8 +51,11 @@ if __name__ == '__main__':
tracks.sort(key=lambda x: x['track']['album']['release_date'], reverse=True)
net.replacePlaylistTracks(tomake['id'], [i['track']['uri'] for i in tracks])
net.changePlaylistDetails(tomake['id'], description=' / '.join(tomake['playlists']))
else:
log.log("config json not found")
if 'SLACKHOOK' in os.environ:
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: config json not found"})
log.dumpLog()
except:

8
getaccesstoken.py Normal file
View File

@ -0,0 +1,8 @@
import spotframework.net.user as userclass
import spotframework.net.network as networkclass
if __name__ == '__main__':
network = networkclass.network(userclass.User())
print(network.user.access_token)

View File

@ -248,6 +248,30 @@ class network:
if len(uris) > 100:
self.addPlaylistTracks(playlistid, uris[100:])
def changePlaylistDetails(self, playlistid, name=None, public=None, collaborative=None, description=None):
log.log("changePlaylistDetails", playlistid)
headers = {"Content-Type": "application/json"}
json = {}
if name is not None:
json['name'] = name
if public is not None:
json['public'] = public
if collaborative is not None:
json['collaborative'] = collaborative
if description is not None:
json['description'] = description
req = self._makePutRequest('changePlaylistDetails', 'playlists/{}'.format(playlistid), json=json,
headers=headers)
return req
def addPlaylistTracks(self, playlistid, uris):
log.log("addPlaylistTracks", playlistid)