add function to get attendance record

This commit is contained in:
Fanani M. Ihsan 2016-06-12 16:35:02 +07:00
parent 0bd1f62ac0
commit 4662212bdc
3 changed files with 24 additions and 3 deletions

12
zk/attendance.py Normal file
View 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)

View File

@ -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")

View File

@ -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)