-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker_library.py
34 lines (30 loc) · 1.18 KB
/
checker_library.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
#!/usr/bin/python
import requests, pickle, smtplib
from email.mime.text import MIMEText
from checker_config import *
def get_access_token():
spotifyData = {'grant_type': 'refresh_token', 'refresh_token': SPOTIFY_REFRESH_TOKEN}
spotifyHeaders = {"Authorization": "Basic " + SPOTIFY_AUTH_TOKEN}
r = requests.post("https://accounts.spotify.com/api/token", data=spotifyData, headers=spotifyHeaders)
spotifyData = r.json()
accessToken = spotifyData['access_token']
spotifyHeaders = {"Authorization": "Bearer " + accessToken, "Accept": "application/json"}
return spotifyHeaders
def load_list():
iof = open(PATH + "/list.p", "rb")
input_list = pickle.load(iof)
iof.close()
return input_list
def save_list(input_list):
iof = open(PATH + "/list.p", "wb")
pickle.dump(input_list, iof, -1)
iof.close()
def send_mail(body, subject, recipient):
msg = MIMEText(body, "plain", "utf-8")
msg['Subject'] = subject
msg['From'] = 'Spotify Song Availability Checker <checker@cagir.me>'
msg['To'] = recipient
s = smtplib.SMTP(MAIL_HOST, MAIL_PORT)
s.login(MAIL_ADDR, MAIL_PASSWD)
s.sendmail(MAIL_ADDR, [recipient], msg.as_string())
s.quit()