Grade Sender

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:

  • Student ID, e.g. 12345678
  • Student Name, e.g. Doe Joe
  • Grade, e.g. Bachelor of class 2014
  • Tutor of the course, e.g. Prof. Zhang
  • Email, e.g. xxx@shanghaitech.edu.cn
  • Score

Configurations


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)

Email Template:


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>
        """

Load CSV file, check template


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

use markdown to preview

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

Try the best to send the score!

ATTENTION: 5 ships / min if connected using SMTP


In [ ]:
try:
    gs.send_score(gs.waiting_list, gs.sent_list)
except:
    print("failed!")
    gs.write_sent_list(gs.waiting_list, gs.sent_list)

Done!