Professional Documents
Culture Documents
In many colleges, we have an attendance system for each subject, and the lack of the same leads to
problems. It is difficult for students to remember the number of leaves taken for a particular subject. If
every time paperwork has to be done to track the number of leaves taken by staff and check whether it is
a lack of attendance or not, it involves a lot of time and is inefficient too.
This article will bring a simple tracker & reminder system for attendance. The input to this system is an
excel sheet containing the students’ mail-id and their number of leaves in each class subject. For say, if a
student will not be allowed to write the exam for a particular subject if he takes more than 3 leaves. This
tracker will send out an email to the student when he takes the second leave as a reminder that only 1
more left with him on that subject. If he takes further leave, both the student and the corresponding staff
receive emails regarding the lack of attendance. The only thing to do is just enter the subject code and
roll number of the student absent from the class and the rest will be taken care of by this tracker system.
Python Modules Used:
Dataset in Use:
• Roll number
• Student mail ID
• Subject {1,2,……..N}
For this article, consider three subjects and their codes as numbers for input:
It is advisable to create a separate mail ID for use as the sender, as Google blocks less secure apps from
signing in to Gmail. Certain permissions have to be given for sending the mail which is risky to do with a
personal mail ID. If you do not give permissions you will end up with “bad credentials” error and will
receive an email, as you see in the screenshot below:
To avoid these issues, follow the steps below:
• Go to the security tab and search for “less secure apps” settings.
• The less secure apps option will be turned off. Click on “Turn on access”.
• You will see the following screen and click on the toggle button to allow non-Google apps use
your Gmail account.
Now all the prerequisites are ready. A Python script has to be written for tracking. Let us do it step by
step.
STEP-WISE IMPLEMENTATION
• Create a function to track attendance: A function for checking the list of absentees against the
threshold condition is required. The updates must take place to the variables declared outside
the function as global variables. Thus, the following lines are written.
Example:
no_of_days : [1,1,2,3] – total number of leaves till date taken by each student in the next list.
• Loop through the list of students (row_num) and for each student check the following
conditions:
o If total no.of.leaves == warning threshold
o If total no.of.leaves > warning threshold
• Here, considering that a student will not be allowed to write exams if he takes more than 2
leaves. Thus, the warning threshold is 2. If a student takes 2 leaves, including today’s absence,
then a reminder mail has to be sent to him, else two mails stating the lack of attendance have to
be sent such that one for student and the other for staff.
• Now, if total no.of.leaves == warning threshold – add the mail Id of the corresponding student to
the list ‘l1’, otherwise, list ‘l3’. If the student’s mail ID is added to list ‘l3’, then the roll number
should be added to the string ‘l2’ to send to the staff.
• Create functions for mailing: Two functions, namely mailstu() and mailstaff() are to be created.
There can be a list of students to whom warnings are to be sent but only one staff member for
that corresponding subject. Thus, two different methods have been written accordingly.
o The smtplib and email.mime modules are used to send the mail in this script.
o MIME emails are widely used now. They can be expanded as Multipurpose Internet Mail
Extensions. They allow a combination of plain text and HTML in the body of the mail. The
email.mime API provides functionalities to structurize emails from Python and also to add
attachments.
o The smtplib module gives the power to connect to a host via port. The ports are predefined
for each domain and appropriate use of it helps to establish connections and send mail. The
port number for yahoo is also 587, but the host will be smtp.mail.yahoo.com
# for students
from_id = ‘cXXXXXXXXXs@gmail.com’
pwd = ‘XXXXXXXXXXXXX’
s = smtplib.SMTP(‘smtp.gmail.com’, 587)
s.starttls()
s.login(from_id, pwd)
to_id = li[i]
message = MIMEMultipart()
message.attach(MIMEText(msg, ‘plain’))
content = message.as_string()
# for staffs
from_id = ‘cXXXXXXXXXXs@gmail.com’
pwd = ‘XXXXXXXX’
to_id = mail_id
message = MIMEMultipart()
message.attach(MIMEText(msg, ‘plain’))
s = smtplib.SMTP(‘smtp.gmail.com’, 587)
s.starttls()
s.login(from_id, pwd)
content = message.as_string()
s.quit()
• The final step is to write a loop that gets input from users until they say no more inputs.
import openpyxl
import smtplib
book = openpyxl.load_workbook('D:\\attendance.xlsx')
sheet = book['Sheet1']
r = sheet.max_row
resp = 1
c = sheet.max_column
l1 = []
# lack of attendance
l2 = ""
l3 = []
m1 = "warning!!! you can take only one more day leave for CI class"
m2 = "warning!!! you can take only one more day leave for python class"
m3 = "warning!!! you can take only one more day leave for DM class"
def savefile():
book.save(r'D:\\attendance.xlsx')
print("saved!")
global staff_mails
global l2
global l3
if no_of_days[student] is 2:
if b is 1:
# mail_id appending
l1.append(sheet.cell(row=row_num[student], column=2).value)
elif b is 2:
l1.append(sheet.cell(row=row_num[student], column=2).value)
mailstu(l1, m2)
else: .
l1.append(sheet.cell(row=row_num[student], column=2).value)
mailstu(l1, m3)
if b is 1:
# adding roll no
l2 = l2+str(sheet.cell(row=row_num[student], column=1).value)
l3.append(sheet.cell(row=row_num[student], column=2).value)
elif b is 2:
l2 = l2+str(sheet.cell(row=row_num[student], column=1).value)
l3.append(sheet.cell(row=row_num[student], column=2).value)
subject = "Python"
else:
l2 = l2+str(sheet.cell(row=row_num[student], column=1).value)
l3.append(sheet.cell(row=row_num[student], column=2).value)
msg2 = "the following students have lack of attendance in your subject : "+l2
mailstu(l3, msg1) # mail to students
# for students
from_id = 'crazygirlaks@gmail.com'
pwd = 'ERAkshaya485'
s.starttls()
s.login(from_id, pwd)
to_id = li[i]
message = MIMEMultipart()
message.attach(MIMEText(msg, 'plain'))
content = message.as_string()
s.quit()
# for staff
from_id = 'crazygirlaks@gmail.com'
pwd = 'ERAkshaya485'
to_id = mail_id
message = MIMEMultipart()
message['Subject'] = 'Lack of attendance report'
message.attach(MIMEText(msg, 'plain'))
s.starttls()
s.login(from_id, pwd)
content = message.as_string()
s.quit()
while resp is 1:
print("1--->CI\n2--->python\n3--->DM")
else:
x = [int(input('roll no :'))]
row_num = []
for student in x:
if y is 1:
m = sheet.cell(row=i, column=3).value
m = m+1
sheet.cell(row=i, column=3).value = m
savefile()
no_of_days.append(m)
row_num.append(i)
elif y is 2:
m = sheet.cell(row=i, column=4).value
m = m+1
no_of_days.append(m)
row_num.append(i)
elif y is 3:
m = sheet.cell(row=i, column=5).value
m = m+1
row_num.append(i)
no_of_days.append(m)
check(no_of_days, row_num, y)
2--->python
3--->DM
enter subject :1
no.of.absentees :2
roll nos :1 3
saved!
saved!
1--->CI
2--->python
3--->DM
enter subject :1
no.of.absentees :1
roll no :1
saved!
1--->CI
2--->python
3--->DM
enter subject :1
no.of.absentees :1
roll no :1
saved!