Mixonomer/spotify/api/spotify.py

33 lines
740 B
Python
Raw Normal View History

from google.cloud import firestore
import logging
import spotify.db.database as database
db = firestore.Client()
logger = logging.getLogger(__name__)
def create_playlist(username, name):
logger.info(f'creating {username} / {name}')
users = [i for i in db.collection(u'spotify_users').where(u'username', u'==', username).stream()]
if len(users) == 1:
net = database.get_authed_network(username)
2019-09-15 15:33:29 +01:00
playlist = net.create_playlist(net.user.username, name)
2019-08-14 22:57:58 +01:00
2019-09-15 15:33:29 +01:00
if playlist is not None:
return playlist
2019-08-14 22:57:58 +01:00
else:
logger.error(f'no response received {username} / {name}')
return None
else:
logger.error(f'{len(users)} users found')
return None