Skip to content

Commit

Permalink
load creds from .env and auto update session playlist url after export
Browse files Browse the repository at this point in the history
  • Loading branch information
SaraBee committed Sep 2, 2020
1 parent 825be81 commit fd3bb57
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion bin/spotify_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
import argparse
import sqlite3
import urllib
import sys
import os
from dotenv import load_dotenv

'''
Script to export session to Spotify playlist
Run from top level project directory (where .env and mcgj.db live)
'''

load_dotenv('.env')


scope = "playlist-modify-public"
Expand Down Expand Up @@ -60,4 +70,11 @@
spotify_tracks.append(spotify_track)

result = sp.user_playlist_add_tracks(user, playlist_id, spotify_tracks)
print(result)

if result:
session_update_sql = 'update sessions set spotify_url = ? where id = ?'
session_update = (playlist['external_urls']['spotify'], session_id)

c.execute(session_update_sql, session_update)
conn.commit()
print('Created playlist: ' + playlist['external_urls']['spotify'])

0 comments on commit fd3bb57

Please sign in to comment.