عکس aut-ce
Sending grades of students privately from .csv file using python.Python
موضوع‌ها
۰
فورک‌ها
۰
ستاره‌ها
۷
تاریخ ایجاد
۲۴ فروردین ۱۳۹۹
آخرین بروزرسانی
۷ ماه قبل
لایسنس
GNU General Public License v3.0

Harpocrates 🙊

The god of silence, secrets and confidentiality

Drone (cloud)

Introduction

This is a python code to send each student's grade privately using smtplib to send emails from python and csv to deal with csv file of grades and students' names.

Send Grades

As you can see in sample.csv you should have a sheet like this (if your column names are different feel free to change them in code):

FIRST_NAME_COLUMN = "نام"
LAST_NAME_COLUMN = "نام خانوادگی"
STUDENT_ID_COLUMN = "شماره دانشجویی"
EMAIL_COLUMN = "ایمیل"
NOTE_COLUMN = "توضیحات"
SKIPPED_ROWS = 2

then you can fill subject.txt and body.html with the text that you want yo send as your email subject and its body. e.g.

<html>
  <body dir="rtl">
    <p>
      با سلام<br />
      دانشجوی عزیز {{ name }}<br />
      نمره تمرین شما
    </p>
    <table>
      <tbody>
        {% for name, grade in grades.items() %}
        <tr>
          <td>{{ name }}</td>
          <td>{{ grade }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    <p>
      در صورت هرگونه اعتراض یا مشکلی با ایمیل زیر در تماس باشید.<br />

      <a href="mailto:parham.alvani@gmail.com">Pahram Alvani</a>
    </p>
  </body>
</html>

As you can see, this is a jinja template and you have variables that is set for each student. Please note that you can check the emails before actually sending them with --dry-run flag.

Enter SMTP/Email Address

After fixing sheets and changing txt files run the program and enter your smtp address and after that your email address and its password in configuration file. e.g.

---
email:
  server: smtp.gmail.com
  username: parham.alvani@gmail.com
  password: secret

Note that if you use gmail you must go to your google account and change Less secure app access here by turning on Allow less secure apps. Otherwise you need to use application-specific passwords.

Installation

You just need to install pandas using pip to run this program.

pip install .
python3 harpocrates

Examples

Here you can see some examples of emails I sent from sample csv files:

example

example