add function to get attendance record
This commit is contained in:
parent
0bd1f62ac0
commit
4662212bdc
12
zk/attendance.py
Normal file
12
zk/attendance.py
Normal file
@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
class Attendance(object):
|
||||
def __init__(self, user_id, timestamp, status):
|
||||
self.user_id = user_id
|
||||
self.timestamp = timestamp
|
||||
self.status = status
|
||||
|
||||
def __str__(self):
|
||||
return self.user_id
|
||||
|
||||
def __repr__(self):
|
||||
return '<Attendance>: {}'.format(self.user_id)
|
10
zk/base.py
10
zk/base.py
@ -5,6 +5,7 @@ from socket import socket, AF_INET, SOCK_DGRAM
|
||||
|
||||
from zk import const
|
||||
from zk.exception import ZKErrorResponse, ZKNetworkError
|
||||
from zk.attendance import Attendance
|
||||
from zk.user import User
|
||||
|
||||
class ZK(object):
|
||||
@ -466,10 +467,15 @@ class ZK(object):
|
||||
attendance_data = ''.join(attendance_data)
|
||||
attendance_data = attendance_data[14:]
|
||||
while len(attendance_data) >= 38:
|
||||
uid, sparator, timestamp, status, space = unpack( '24sc4sc10s', attendance_data.ljust(40)[:40])
|
||||
uid = uid.strip('\x00|\x01\x10x')
|
||||
user_id, sparator, timestamp, status, space = unpack( '24sc4sc10s', attendance_data.ljust(40)[:40])
|
||||
|
||||
user_id = user_id.strip('\x00|\x01\x10x')
|
||||
timestamp = self.__decode_time(timestamp)
|
||||
status = int(status.encode("hex"), 16)
|
||||
|
||||
attendance = Attendance(user_id, timestamp, status)
|
||||
attendances.append(attendance)
|
||||
|
||||
attendance_data = attendance_data[40:]
|
||||
else:
|
||||
raise ZKErrorResponse("Invalid response")
|
||||
|
@ -9,5 +9,8 @@ class User(object):
|
||||
self.group_id = group_id
|
||||
self.user_id = user_id
|
||||
|
||||
def __str__(self):
|
||||
def __repr__(self):
|
||||
return self.name
|
||||
|
||||
def __repr__(self):
|
||||
return '<User>: {}'.format(self.name)
|
Loading…
Reference in New Issue
Block a user