-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-emails.py
42 lines (35 loc) · 1.08 KB
/
send-emails.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
#!/usr/bin/python
'''
This file is for emailing someone when a spot opens in a class they are watching
'''
import smtplib
from class_search_web_scrapping import GetClasses, GetCurrentSemester
crn = '24680'
openSpots = 0
courseName = 'Unamed Course'
classes = GetClasses(GetCurrentSemester(), "CSE", "A", "0ANY", "A", "M")
for course in classes:
if course['CRN'] == crn:
openSpots = course['Opn']
courseName = course['Title']
if int(openSpots) > 0:
sender = 'DO-NOT-REPLY@ndreviews.com'
receivers = ['dmattia@nd.edu', 'david.j.mattia.2@nd.edu']
subject = 'A spot has opened up!'
body = "A spot has recently opened up in a class you are watching on ndreviews.com\n\
The course %s now has %s open spots\n\
\n\
Good luck NOVOing as quick as you can!\n\
-ndreviews staff" % (courseName, openSpots)
for recipient in receivers:
message = """\
from: %s
to: %s
subject: %s
%s
""" % (sender, recipient, subject, body)
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Spots are now open. Email sent."
else:
print "No spots open. No email sent."