-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrefresh.py
44 lines (34 loc) · 915 Bytes
/
refresh.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
#########################
# Imports
#########################
import requests, json, base64
from secrets import *
#########################
# Headers
#########################
headers = {
'Authorization': "Basic " + str(base64.urlsafe_b64encode((CLIENT_ID + ':' + CLIENT_SECRET).encode())).decode()
}
data = [
('grant_type', 'refresh_token'),
('refresh_token', REFRESH_TOKEN),
]
#########################
# Requests
#########################
response = requests.post('https://accounts.spotify.com/api/token', headers=headers, data=data)
json = json.loads(response.text)
#########################
# Populating
#########################
f = open("secrets.py", 'r')
i = f.readlines()
o = ""
f.close()
for line in i:
if line == "ACCESS_TOKEN = \"%s\"\n" % ACCESS_TOKEN:
line = "ACCESS_TOKEN = \"%s\"\n" % json["access_token"]
o += line
f = open("secrets.py", 'w')
f.write(o)
f.close()