-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
44 lines (32 loc) · 1.42 KB
/
utilities.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
35
36
37
38
39
40
41
42
43
44
from flask import Flask, session
from access import CLIENT_ID, CLIENT_SECRET
import requests
def get_id(input_name, input_type):
"""Returns JSON object from Spotify with track/artist data"""
headers = {'Authorization': 'Bearer ' + session['token']}
params = {
'q': input_name,
'type': input_type,
'limit': 10
}
resp = requests.get('https://api.spotify.com/v1/search',
params=params, headers=headers).json()
resp['input_type'] = input_type
return resp
def get_genres():
"""Returns a list of Spotify music genre tuples in format [('house','House')]"""
headers = {'Authorization': 'Bearer ' + session['token']}
raw = requests.get(
'https://api.spotify.com/v1/recommendations/available-genre-seeds', headers=headers).json()
genres = [(genre, genre.capitalize()) for genre in raw['genres']]
genres[0] = ('', 'Genre (optional)')
return genres
def get_keys():
"""Returns a list of tuples of music notational keys as defined by Spotify"""
keys = [('', 'Select a Song Key'), ('0', 'C'), ('1', 'C#'), ('2', 'D'), ('3', 'D#'), ('4', 'E'),
('5', 'F'), ('6', 'F#'), ('7', 'G'), ('8', 'G#'), ('9', 'A'), ('10', 'A#'), ('11', 'B')]
return keys
def get_modes():
"""Returns a list of tuples of modes as defined by Spotify"""
modes = [('', 'Select Major or Minor Key'), ('0', 'Minor'), ('1', 'Major')]
return modes