2019-08-02 12:54:18 +01:00
|
|
|
from google.cloud import firestore
|
|
|
|
|
2019-08-17 18:30:13 +01:00
|
|
|
import logging
|
|
|
|
|
2019-10-19 17:14:11 +01:00
|
|
|
import music.db.database as database
|
2019-08-10 17:53:50 +01:00
|
|
|
|
2019-08-02 12:54:18 +01:00
|
|
|
db = firestore.Client()
|
|
|
|
|
2019-08-17 18:30:13 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-08-02 12:54:18 +01:00
|
|
|
|
|
|
|
def create_playlist(username, name):
|
2019-08-17 18:30:13 +01:00
|
|
|
logger.info(f'creating {username} / {name}')
|
|
|
|
|
2019-10-23 14:44:17 +01:00
|
|
|
user = database.get_user(username)
|
|
|
|
if user is not None:
|
2019-10-07 12:21:26 +01:00
|
|
|
net = database.get_authed_spotify_network(username)
|
2019-08-02 12:54:18 +01:00
|
|
|
|
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:
|
2019-08-17 18:30:13 +01:00
|
|
|
logger.error(f'no response received {username} / {name}')
|
|
|
|
return None
|
2019-08-02 12:54:18 +01:00
|
|
|
|
2019-08-10 17:53:50 +01:00
|
|
|
else:
|
2019-10-23 14:44:17 +01:00
|
|
|
logger.error(f'{username} not found')
|
2019-08-17 18:30:13 +01:00
|
|
|
return None
|