-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.py
63 lines (46 loc) · 1.41 KB
/
notification.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pyodbc
from email.message import EmailMessage
import ssl
import smtplib
connection_string = ""
table_name = ''
def fetch_entries(conn):
cursor = conn.cursor()
cursor.execute("SELECT * FROM AllMenuData WHERE Name LIKE '%chicken%' OR Name LIKE '%kiwi%'")
rows = cursor.fetchall()
conn.commit()
conn.close()
return rows
def send_text():
email_sender = ""
email_password = ""
email_receiver = ''
subject = "DiningCourtMessenger"
em = EmailMessage()
em['From'] = email_sender
em['To'] = email_receiver
em['subject'] = subject
context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
smtp.login(email_sender, email_password)
for entry in entries:
date = entry[0]
dining_court = entry[1]
meal = entry[2]
food = entry[3]
body = f"""
{food} is being served at {dining_court} dining court for {meal} today, {date}!
"""
em.set_content(body)
smtp.sendmail(email_sender, email_receiver, em.as_string())
def main():
conn = pyodbc.connect(connection_string)
entries = fetch_entries(conn)
if len(entries) == 0:
print('No matches found.')
return
print(entries)
send_text()
print('finished!')
if __name__ == "__main__":
main()