From 5d3aae38845dc5be25497b39fdc50bbb99cafff8 Mon Sep 17 00:00:00 2001 From: "Fanani M. Ihsan" Date: Wed, 25 May 2016 01:32:06 +0700 Subject: [PATCH] add function set_user --- test.py | 3 +++ zk/base.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/test.py b/test.py index 27420f2..ff605b3 100644 --- a/test.py +++ b/test.py @@ -11,6 +11,9 @@ if conn.get('status'): print conn print zk.disable_device() print 'Firmware Version: : {}'.format(zk.get_firmware_version()) + # Load test create 1000 users + for i in range(1, 1000+1): + zk.set_user(uid=i, user_id='{}'.format(i), name='user #{}'.format(i), password='123456', privilege=14) # print 'Restarting device' # print zk.restart() # print 'Turning off device' diff --git a/zk/base.py b/zk/base.py index aac786e..1bf9e8f 100644 --- a/zk/base.py +++ b/zk/base.py @@ -202,6 +202,17 @@ class ZK(object): else: return cmd_response + def set_user(self, uid, privilege, password='', name='', card_num=chr(1), group='', timezone='', user_id=''): + command = const.CMD_USER_WRQ + command_string = pack('sss8s28ss7sx8s16s', chr(uid % 256), chr(uid >> 8), chr(privilege), password, name, card_num, group, user_id, timezone ) + cmd_response = self.__send_command(command=command, command_string=command_string, response_size=1024) + cmd_response['data'] = '' + if cmd_response.get('status'): + cmd_response['message'] = 'new user created' + return cmd_response + else: + return cmd_response + # def __get_size_user(self): # """Checks a returned packet to see if it returned CMD_PREPARE_DATA, # indicating that data packets are to be sent