51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
# K210考勤数据查看工具
|
|
# 用于读取和显示SD卡中的考勤记录
|
|
|
|
import os
|
|
|
|
ATTENDANCE_FILE = "/sd/attendance_records.csv"
|
|
|
|
def view_attendance_records(limit=20):
|
|
"""查看最近的考勤记录"""
|
|
try:
|
|
if ATTENDANCE_FILE not in os.listdir("/sd"):
|
|
print("No attendance file found!")
|
|
return
|
|
|
|
with open(ATTENDANCE_FILE, "r") as f:
|
|
lines = f.readlines()
|
|
|
|
print("=" * 50)
|
|
print("Attendance Records (Total: {})".format(len(lines) - 1))
|
|
print("=" * 50)
|
|
|
|
# 显示表头
|
|
if len(lines) > 0:
|
|
print(lines[0].strip())
|
|
print("-" * 50)
|
|
|
|
# 显示最近的记录
|
|
start = max(1, len(lines) - limit)
|
|
for i in range(start, len(lines)):
|
|
print(lines[i].strip())
|
|
|
|
print("=" * 50)
|
|
|
|
except Exception as e:
|
|
print("Error reading file:", e)
|
|
|
|
def clear_attendance_records():
|
|
"""清空考勤记录(保留表头)"""
|
|
try:
|
|
with open(ATTENDANCE_FILE, "w") as f:
|
|
f.write("Timestamp,Student_ID,Name,Confidence,Status\n")
|
|
print("Attendance records cleared!")
|
|
except Exception as e:
|
|
print("Error clearing file:", e)
|
|
|
|
# 显示最近20条记录
|
|
view_attendance_records(20)
|
|
|
|
# 如果需要清空记录,取消下面这行的注释
|
|
# clear_attendance_records()
|