From 793b03c28d76d4073ec957c5ee52be080f00cbe5 Mon Sep 17 00:00:00 2001 From: aj Date: Sun, 26 May 2019 20:42:01 +0100 Subject: [PATCH] added slack notifying, playlist description writing --- generateplaylists.py | 7 +++++++ getaccesstoken.py | 8 ++++++++ spotframework/net/network.py | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 getaccesstoken.py diff --git a/generateplaylists.py b/generateplaylists.py index 865f9b7..ab2c742 100644 --- a/generateplaylists.py +++ b/generateplaylists.py @@ -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: diff --git a/getaccesstoken.py b/getaccesstoken.py new file mode 100644 index 0000000..a795699 --- /dev/null +++ b/getaccesstoken.py @@ -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) diff --git a/spotframework/net/network.py b/spotframework/net/network.py index d282f79..b06a416 100644 --- a/spotframework/net/network.py +++ b/spotframework/net/network.py @@ -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)