Skip to content

Commit 34accc3

Browse files
committed
Chapter 16 finished
1 parent 321d1df commit 34accc3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

16-email-sms/duesRecords.xlsx

8.69 KB
Binary file not shown.

16-email-sms/sendDuesReminders.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! python3
2+
# sendDuesReminders.py - Sends emails based on their status in spreadsheet.
3+
4+
import openpyxl, smtplib, sys
5+
6+
# Open the spreadsheet and get the latest dues status.
7+
wb = openpyxl.load_workbook('duesRecords.xlsx')
8+
sheet = wb.get_sheet_by_name('Sheet1')
9+
10+
lastCol = sheet.get_highest_column()
11+
latestMonth = sheet.cell(row=1, column=lastCol).value
12+
13+
unpaidMembers = {}
14+
# Check each member's payment status
15+
for r in range(2, sheet.get_highest_row() + 1):
16+
payment = sheet.cell(row=r, column=lastCol).value
17+
if payment != 'paid':
18+
name = sheet.cell(row=r, column=1).value
19+
email = sheet.cell(row=r, column=2).value
20+
unpaidMembers[name] = email
21+
22+
# Log in to email account.
23+
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
24+
smtpObj.ehlo()
25+
smtpObj.starttls()
26+
smtpObj.login('my_email_address@gmail.com', sys.argv[1])
27+
28+
# Send out reminder emails.
29+
for name, email in unpaidMembers.items():
30+
body = 'Subject: %s dues unpaid.\nDear %s,\nRecords show that you have not paid dues for %s. Please make this payment as soon as possible. Thank you!' % (latestMonth, name, latestMonth)
31+
print('Sending email to %s...' % email)
32+
sendmailStatus = smtpObj.sendmail('my_email_address@gmail.com', email, body)
33+
34+
if sendmailStatus != {}:
35+
print('There was a problem sending email to %s: %s' % (email, sendmailStatus))
36+
smtpObj.quit()

16-email-sms/textMyself.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! python3
2+
# textMyself.py - Defines the textmyself() function that texts a message
3+
# passed to it as a string.
4+
5+
# Preset values:
6+
accountSID = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
7+
authToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
8+
myNumber = '+15559998888'
9+
twilioNumber = '+15552225678'
10+
11+
from twilio.rest import TwilioRestClient
12+
13+
def textmyself(message):
14+
twilioCli = TwilioRestClient(accountSID, authToken)
15+
twilioCli.messages.create(body=message, from_=twilioNumber, to=myNumber)

0 commit comments

Comments
 (0)