handling for playlist references

This commit is contained in:
aj 2019-08-04 02:02:30 +01:00
parent cc390e2088
commit 143db275f8
2 changed files with 33 additions and 3 deletions

8
google_test.py Normal file
View File

@ -0,0 +1,8 @@
import main
main.run_user_playlist({
'data': 'ELECTRONIC',
'attributes': {
'username': 'andy'
}
}, None)

View File

@ -12,6 +12,8 @@ from spotframework.net.user import User
db = firestore.Client() db = firestore.Client()
captured_playlists = []
def run_user_playlist(username, playlist_name): def run_user_playlist(username, playlist_name):
@ -34,7 +36,7 @@ def run_user_playlist(username, playlist_name):
if playlist_dict['playlist_id'] is None: if playlist_dict['playlist_id'] is None:
raise Exception('no playlist id to populate') raise Exception('no playlist id to populate')
if len(playlist_dict['parts']) == 0: if len(playlist_dict['parts']) == 0 and len(playlist_dict['playlist_references']) == 0:
raise Exception('no playlists to use for creation') raise Exception('no playlists to use for creation')
spotify_keys = db.document('key/spotify').get().to_dict() spotify_keys = db.document('key/spotify').get().to_dict()
@ -54,11 +56,16 @@ def run_user_playlist(username, playlist_name):
else: else:
processors.append(SortReverseReleaseDate()) processors.append(SortReverseReleaseDate())
global captured_playlists
captured_playlists = []
submit_parts = playlist_dict['parts'] + generate_parts(users[0].id, playlist_dict['name'])
if playlist_dict['type'] == 'recents': if playlist_dict['type'] == 'recents':
boundary_date = datetime.datetime.now() - datetime.timedelta(days=int(playlist_dict['day_boundary'])) boundary_date = datetime.datetime.now() - datetime.timedelta(days=int(playlist_dict['day_boundary']))
tracks = engine.get_recent_playlist(boundary_date, playlist_dict['parts'], processors) tracks = engine.get_recent_playlist(boundary_date, submit_parts, processors)
else: else:
tracks = engine.make_playlist(playlist_dict['parts'], processors) tracks = engine.make_playlist(submit_parts, processors)
engine.execute_playlist(tracks, playlist_dict['playlist_id']) engine.execute_playlist(tracks, playlist_dict['playlist_id'])
engine.change_description(playlist_dict['parts'], playlist_dict['playlist_id']) engine.change_description(playlist_dict['parts'], playlist_dict['playlist_id'])
@ -68,3 +75,18 @@ def run_user_playlist(username, playlist_name):
else: else:
raise Exception('not one user found') raise Exception('not one user 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]
return_parts = playlist_doc['parts']
captured_playlists.append(name)
for i in playlist_doc['playlist_references']:
if i not in captured_playlists:
return_parts += generate_parts(user_id, i)
return return_parts