From 2768854a9eefdf788214edd08bfac80b627d487c Mon Sep 17 00:00:00 2001 From: aj Date: Mon, 5 Aug 2019 23:08:57 +0100 Subject: [PATCH] duplicate removal of submit_parts, sorting for description --- spotframework/google/run_user_playlist.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spotframework/google/run_user_playlist.py b/spotframework/google/run_user_playlist.py index 47737d6..96a2c59 100644 --- a/spotframework/google/run_user_playlist.py +++ b/spotframework/google/run_user_playlist.py @@ -59,32 +59,37 @@ def run_user_playlist(username, playlist_name): submit_parts = playlist_dict['parts'] + generate_parts(users[0].id, playlist_dict['name']) + submit_parts = [i for i in {j for j in submit_parts}] + if playlist_dict['type'] == 'recents': boundary_date = datetime.datetime.now() - datetime.timedelta(days=int(playlist_dict['day_boundary'])) tracks = engine.get_recent_playlist(boundary_date, submit_parts, processors, include_recommendations=playlist_dict['include_recommendations'], - recommendation_limit=playlist_dict['recommendation_sample']) + recommendation_limit=int(playlist_dict['recommendation_sample'])) else: tracks = engine.make_playlist(submit_parts, processors, include_recommendations=playlist_dict['include_recommendations'], - recommendation_limit=playlist_dict['recommendation_sample']) + recommendation_limit=int(playlist_dict['recommendation_sample'])) engine.execute_playlist(tracks, playlist_dict['playlist_id']) - engine.change_description({i for i in submit_parts}, playlist_dict['playlist_id']) + engine.change_description(sorted(submit_parts), playlist_dict['playlist_id']) else: - raise Exception('multiple playlists found') + raise Exception('multiple/no playlists found') else: - raise Exception('not one user found') + raise Exception('multiple/no user(s) found') def generate_parts(user_id, name): - playlist_doc = [i.to_dict() for i in db.document(u'spotify_users/{}'.format(user_id)).collection(u'playlists').where(u'name', '==', name).stream()][0] + playlist_doc = [i.to_dict() for i in + db.document(u'spotify_users/{}'.format(user_id)) + .collection(u'playlists') + .where(u'name', '==', name).stream()][0] return_parts = playlist_doc['parts']