--- /dev/null
+*.py filter=scrub
--- /dev/null
+#! /bin/python
+
+import requests
+import os
+
+id = input('Enter the client id: ');
+secret = input('Enter the client secret: ');
+code = input('Enter the auth code (obtained from get-auth-code.py): ');
+callback = input('Enter the callback uri: ');
+
+params = {'client_id':id,
+ 'client_secret':secret,
+ 'grant_type':"authorization_code",
+ 'code':code,
+ 'redirect_uri':callback}
+
+r = requests.post(url = "https://accounts.spotify.com/api/token", data = params)
+
+print(r.text);
--- /dev/null
+#! /bin/python
+
+import webbrowser, os
+
+id = input('Enter client id: ');
+secret = input('Enter client secret: ');
+callback = input('Enter callback url: ');
+scopes = input('Enter space-separated scopes: ');
+
+webbrowser.get().open("https://accounts.spotify.com/authorize/client_id=" + id + "&response_type=code&redirect_uri=" + callback + "&scope=" + scopes);
+
+print('A browser window has been opened asking you to log in to Spotify. Once logged in, you will be redirected to the callback uri you gave, with a parameter containing the auth code.')
--- /dev/null
+#! /bin/python
+
+import requests, json, collections
+
+id = "censored"
+secret = "censored"
+Token = collections.namedtuple('token', ['access', 'refresh', 'err'])
+
+def refresh() :
+
+ authfile = open('./.auth', 'r+') # current refresh token is kept in .auth
+ rt = authfile.read().splitlines()[0];
+
+ params = {'client_id':id,
+ 'client_secret':secret,
+ 'grant_type':"refresh_token",
+ 'refresh_token':rt}
+
+ data = json.loads(requests.post(url = "https://accounts.spotify.com/api/token", data = params).text)
+ try:
+ authfile.write(data['refresh_token']); # refresh token is not updated if delta t < 3600ms
+ except:
+ pass
+ # print("Refresh token unchanged")
+ return(data['access_token']);
+
+header = {'Authorization': "Authorization: Bearer " + refresh()}
+response = requests.get("https://api.spotify.com/v1/me/player/recently-played", headers = header).text
+data = json.loads(response)
+# open('./sampleoutput.json', 'w').write(response); # for debugging
+print("\"" + data['items'][0]['track']['name'] + "\" by " + data['items'][0]['track']['artists'][0]['name']);
--- /dev/null
+#! /bin/python
+
+import requests
+
+id = input('Enter the client id: ');
+secret = input('Enter the client secret: ');
+token = input('Enter the refresh token (obtained from get-access-token.py): ');
+
+params = {'client_id':id,
+ 'client_secret':secret,
+ 'grant_type':"refresh_token",
+ 'refresh_token':token}
+
+r = requests.post(url = "https://accounts.spotify.com/api/token", data = params)
+
+print(r.text);