This is a self-developed script to parse the grading sheet, to compose and to send the score report to student. A typical scoresheet in ShanghaiTech University has the following fields:
In [ ]:
import gradeSender as gs
gs.DEBUG = True # Switch to False when deployed :D
gs.user_account = "xyz@whatever.com"
gs.user_password = "password/autherization_code" # autherization code if using 163, qq, etc.
gs.user_smtp_server = "smtp.whatever.com" # some may use mail.whatever.com as an alternative
gs.user_smtp_port = "" # if not provided, server use mail.whatever.com instead
gs.file_to_open = 'example.csv' # currently only support csv file parsing
gs.sent_list_file = './sent_list.txt'
gs.waiting_list, gs.sent_list = {}, {}
# Try to connect, continue if succeed, check if failed
gs.server = gs.connect(gs.user_smtp_server, gs.user_smtp_port, gs.user_account, gs.user_password)
In [ ]:
# Email template, you may change it as you like
# make sure it has correspondence fields for formatting
gs.subject = "yourSubject"
gs.content = """
<html>
<head></head>
<body>
<p>Hi {}, <br><br>
Your ID is <strong>{}</strong>,the score is <strong>{}</strong>,<br>
If you have question, pls come for <strong>WHO</strong> at <strong>WHEN</strong>, in <strong>WHERE</strong><br>
Make appointment ahead of time
</p>
</body>
</html>
"""
In [ ]:
gs.waiting_list, gs.sent_list = gs.initiate(gs.file_to_open, gs.waiting_list, )
temp = gs.waiting_list[0]
print(gs.content.format(temp[1], temp[0], temp[3])) # Name, ID, Score
Hi Doe Joe,
Your ID is 97XXXX63, the score is 99,
If you have question, pls come for WHO at WHEN, in WHERE
Make appointment ahead of time
In [ ]:
try:
gs.send_score(gs.waiting_list, gs.sent_list)
except:
print("failed!")
gs.write_sent_list(gs.waiting_list, gs.sent_list)