Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions zk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,10 +1574,11 @@ def read_with_buffer(self, command, fct=0 ,ext=0):
if self.verbose: print ("_read w/chunk %i bytes" % start)
return b''.join(data), start

def get_attendance(self):
def get_attendance(self, last_records=0):
"""
return attendance record


:param last_records: Indicates the number of registers to obtain, located in the last memory spaces. If is value is zero, filtering is not applied.
:return: List of Attendance object
"""
self.read_sizes()
Expand All @@ -1593,8 +1594,17 @@ def get_attendance(self):
total_size = unpack("I", attendance_data[:4])[0]
record_size = total_size/self.records
if self.verbose: print ("record_size is ", record_size)

start_pos = 0
if(last_records > 0 and last_records < self.records):
skip_records = self.records - last_records
start_pos += skip_records

attendance_data = attendance_data[4:]

if record_size == 8:
if(start_pos > 0):
attendance_data = attendance_data[(8 * start_pos):]
while len(attendance_data) >= 8:
uid, status, timestamp, punch = unpack('HB4sB', attendance_data.ljust(8, b'\x00')[:8])
if self.verbose: print (codecs.encode(attendance_data[:8], 'hex'))
Expand All @@ -1608,6 +1618,8 @@ def get_attendance(self):
attendance = Attendance(user_id, timestamp, status, punch, uid)
attendances.append(attendance)
elif record_size == 16:
if(start_pos > 0):
attendance_data = attendance_data[(16 * start_pos):]
while len(attendance_data) >= 16:
user_id, timestamp, status, punch, reserved, workcode = unpack('<I4sBB2sI', attendance_data.ljust(16, b'\x00')[:16])
user_id = str(user_id)
Expand All @@ -1629,6 +1641,8 @@ def get_attendance(self):
attendance = Attendance(user_id, timestamp, status, punch, uid)
attendances.append(attendance)
else:
if(start_pos > 0):
attendance_data = attendance_data[(40 * start_pos):]
while len(attendance_data) >= 40:
uid, user_id, status, timestamp, punch, space = unpack('<H24sB4sB8s', attendance_data.ljust(40, b'\x00')[:40])
if self.verbose: print (codecs.encode(attendance_data[:40], 'hex'))
Expand Down