-
Notifications
You must be signed in to change notification settings - Fork 0
/
shuffler.py
34 lines (25 loc) · 929 Bytes
/
shuffler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import spotipy
import spotipyFuncs as msp
import numpy as np
import pandas as pd
import argparse
# Create arguement parser
parser = argparse.ArgumentParser()
# Accept number of songs as input
parser.add_argument("--n_songs", type=int,
help="Number of songs in playlist",
default = 10)
args = parser.parse_args()
# Load spreadsheet
weightings=pd.read_excel('weightings.xlsx')
# Calculate total of weightings for normalisation
total_weight = weightings['Weighting'].sum()
# Normalise weightings to probability (p=weighting/total_weight)
probs = weightings['Weighting']/total_weight
ids = list(weightings['URI'])
# Sample n_songs without replacement with probability probs
new_ids = np.random.choice(ids, size=args.n_songs, p=probs, replace=False)
# Loginto spotipy
sp = msp.spotify_login()
# Play shuffled songs
sp.start_playback(uris=list(new_ids))