It took half a year to write an electronic attendance system in Python

Today, I will share with you a more interesting Python application. I wrote an electronic attendance system in Python. The source code is given in the article below. Remember to like and favorite~

Electronic Time Attendance Complete Code

The complete code and data have been placed in the background, just reply by keyword

If you want to join the technical exchange, the best way to remark when adding is: source + interest direction, which is convenient to find like-minded friends

Method ①, Add WeChat ID: dkl88191, Remarks: From CSDN+ Electronic Attendance
Method ②, WeChat Search Public Number: Python Learning and Data Mining, Background Reply: Electronic Attendance

Project Description

The school now needs to implement an electronic attendance system. Considering that your class has already learned Python, the big data application development language, you are ready to implement some student attendance functions. After communicating with the teacher, you learned that:

(1) At present, some functions of the system have been realized by the seniors. You only need to complete the remaining functions. The functions that you need to complete will be used.

Mark it in the form of #todo, and the function of this place will be listed after todo, in the following form.

insert image description here

(2) The student information is stored in the stu_infos.csv file. The first line is the column name line, and each subsequent line is the information of a student, including student ID, name, and password. The content format is as follows:

picture

(3) The attendance record will eventually be saved to the attendance.csv file. The first row is the column name row, and each subsequent row represents the attendance information of a student, including student ID, name, time, and attendance status (only attendance, late, Four states of leave and absence). The content format is as follows:

picture

(4) Student information needs to be loaded into the student_infos list first, each element in student_info is a dictionary, the keys in the dictionary are the respective column names, and the value is the content of each row, student_infos constructed according to the sample data The list is as follows.

picture

(5) There are a total of two Python files on the teacher side of the attendance system, a main.py file, which is used as the entry program file to realize the main framework. The main process is: load data, log in and add attendance data; a stu_attendance.py file, which defines Data loading, logging and other functions.

answer requirements

  1. Add a line of your own information at the end of the stu_info.csv file, write your password at will, and your name and student ID must be your own

  2. Look at the todo comments in the two Python files, add the appropriate code, and finally provide the added code.

  3. Test program function, provide program running screenshots. When performing login verification, use your own student ID for login verification, and you need to test the following two branches: the case where the login fails 3 times, and the attendance data is successfully added after the login is successful.

Additional features

Add a query function, enter a student's name to get his attendance data information

import module

import csv
import time
student_infos = []

Download Data

def load_stu_info():
    """
    加载学生信息
    从stu_infos.csv文件中加载数据
    :return: 无
    """
    with open(r"stu_infos.csv", encoding='utf-8-sig') as file:
        f_csv = csv.reader(file)
        header = next(f_csv)
        for row in f_csv:
            student_info = {
    
    }
            for index in range(3):
                student_info[header[index]] = row[index]
            student_infos.append(student_info)

Log in

def login():
    """
    用户使用学号和密码进行登录
    最多让用户登录三次,如果连续三次都登录失败(用户名或者密码错误),只要密码和用户都正确表示登录成功
    :return:登录成功返回True和学号,三次都登录失败返回False和None
    """
    retry_time = 0
    while retry_time < 3:
        user_no = input('请输入登录账号:')
        password = input('请输入密码:')
        for i in student_infos:
            if i['no']==user_no and i['password']==password:
                return True,user_no
        print('用户名或者密码错误!!!请重新输入。')
        retry_time += 1
    else:
        return False, None

Attendance record writing

def add(user_no):
    for x in student_infos:
        if user_no==x['no']:
            name=x['name']
            break
    times=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    choices=['出勤','迟到','请假','缺勤']
    a=int(input("\t该学生出勤情况:1-出勤\t2-迟到\t3-请假\t4-缺勤:"))
    if a==1:
        data=choices[0]
    elif a==2:
        data=choices[1]
    elif a==3:
        data=choices[2]
    else:
        data=choices[3]
    with open(r"attendance.csv",'a+',newline='', encoding='utf-8') as f:
        wf = csv.writer(f)
        wf.writerow([user_no,name,times,data])#写入一行数据
        print("{}同学{}数据已经写入成功!操作时间是{}".format(name,data,times))

Query attendance records

def select():
    student = []
    with open(r"attendance.csv", encoding='utf-8-sig') as file:
        f_csv = csv.reader(file)
        header = next(f_csv)
        for row in f_csv:
            students = {
    
    }
            for index in range(4):
                students[header[index]] = row[index]
            student.append(students)
        name=input("请输入你需要查找的姓名:")
        print("  学号\t\t姓名\t\t操作时间\t\t出勤状态")
        for a in student:
            if a['name']==name:
                print(a['no']+'\t'+a['name']+'\t'+a['time']+'\t\t'+a['state'])
            else:
                print("无此人!!!")
                break

main function main.py

from student.stu_attendance import *
if __name__ == '__main__':
    load_stu_info()
    success, stu_no = login()
    print(stu_no)
    if success:
        print('登录成功!')
        add(stu_no)
        q=int(input("你想要查询出勤数据吗?\tyes(1)--no(0)"))
        if q==1:
            select()
        else:
            print("欢迎下次登录电子考勤系统")
    else:
        print('登录失败')

See how it works!

insert image description here

insert image description here

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/m0_59596937/article/details/127471632