pep8 standarization
This commit is contained in:
parent
5abb3b5134
commit
c6b8cf1200
61
README.md
61
README.md
@ -1,6 +1,6 @@
|
|||||||
# pyzk
|
# pyzk
|
||||||
|
|
||||||
pyzk is unofficial library of zksoftware the fingerprint attendance machine.
|
pyzk is an unofficial library of zksoftware the fingerprint attendance machine.
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
@ -14,25 +14,24 @@ Complete documentation can be found at [Readthedocs](http://pyzk.readthedocs.io/
|
|||||||
|
|
||||||
# Api Usage
|
# Api Usage
|
||||||
|
|
||||||
Create ZK object and you will ready to call api.
|
Create an ZK instnace and you will ready to call api.
|
||||||
|
|
||||||
* Basic Usage
|
* Basic Usage
|
||||||
```
|
```
|
||||||
import zk
|
from zk import ZK, const
|
||||||
from zk import const
|
|
||||||
|
|
||||||
conn = False
|
sys.path.append("zk")
|
||||||
zk = zk.ZK(ip='192.168.1.201', port=4370, timeout=5)
|
|
||||||
|
conn = None
|
||||||
|
zk = ZK('192.168.1.10', port=4370, timeout=5)
|
||||||
try:
|
try:
|
||||||
|
print 'Connecting to device ...'
|
||||||
conn = zk.connect()
|
conn = zk.connect()
|
||||||
|
print 'Disabling device ...'
|
||||||
# disable (lock) the device, make sure no activity when process run
|
conn.disable_device()
|
||||||
zk.disable_device()
|
print 'Firmware Version: : {}'.format(conn.get_firmware_version())
|
||||||
|
# print '--- Get User ---'
|
||||||
# Do another task here
|
users = conn.get_users()
|
||||||
firmware_version = zk.get_firmware_version()
|
|
||||||
print 'Firmware Version: : {}'.format(firmware_version)
|
|
||||||
users = zk.get_users()
|
|
||||||
for user in users:
|
for user in users:
|
||||||
privilege = 'User'
|
privilege = 'User'
|
||||||
if user.privilege == const.USER_ADMIN:
|
if user.privilege == const.USER_ADMIN:
|
||||||
@ -45,67 +44,69 @@ try:
|
|||||||
print ' Group ID : {}'.format(user.group_id)
|
print ' Group ID : {}'.format(user.group_id)
|
||||||
print ' User ID : {}'.format(user.user_id)
|
print ' User ID : {}'.format(user.user_id)
|
||||||
|
|
||||||
zk.enable_device()
|
print "Voice Test ..."
|
||||||
|
conn.test_voice()
|
||||||
|
print 'Enabling device ...'
|
||||||
|
conn.enable_device()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "Process terminate : {}".format(e)
|
print "Process terminate : {}".format(e)
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
zk.disconnect()
|
conn.disconnect()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
* Connect/Disconnect
|
* Connect/Disconnect
|
||||||
|
|
||||||
```
|
```
|
||||||
zk.connect()
|
conn = zk.connect()
|
||||||
zk.disconnect()
|
conn.disconnect()
|
||||||
```
|
```
|
||||||
|
|
||||||
* Disable/Enable Connected Device
|
* Disable/Enable Connected Device
|
||||||
|
|
||||||
```
|
```
|
||||||
zk.disable_device()
|
conn.disable_device()
|
||||||
zk.enable_device()
|
conn.enable_device()
|
||||||
```
|
```
|
||||||
|
|
||||||
* Ger Firmware Version
|
* Ger Firmware Version
|
||||||
|
|
||||||
```
|
```
|
||||||
zk.get_firmware_version()
|
conn.get_firmware_version()
|
||||||
```
|
```
|
||||||
|
|
||||||
* User Operation
|
* User Operation
|
||||||
|
|
||||||
```
|
```
|
||||||
# Create user
|
# Create user
|
||||||
zk.set_user(uid=1, name='Fanani M. Ihsan', privilege=const.USER_ADMIN, password='12345678', group_id='', user_id='123')
|
conn.set_user(uid=1, name='Fanani M. Ihsan', privilege=const.USER_ADMIN, password='12345678', group_id='', user_id='123')
|
||||||
# Get all users (will return list of User object)
|
# Get all users (will return list of User object)
|
||||||
users = zk.get_users()
|
users = conn.get_users()
|
||||||
# Delete User
|
# Delete User
|
||||||
zk.delete_user(uid=1)
|
conn.delete_user(uid=1)
|
||||||
```
|
```
|
||||||
|
|
||||||
* Attendance Record
|
* Attendance Record
|
||||||
```
|
```
|
||||||
# Get attendances (will return list of Attendance object)
|
# Get attendances (will return list of Attendance object)
|
||||||
attendances = zk.get_attendance()
|
attendances = conn.get_attendance()
|
||||||
# Clear attendances record
|
# Clear attendances record
|
||||||
zk.clear_attendance()
|
conn.clear_attendance()
|
||||||
```
|
```
|
||||||
|
|
||||||
* Test voice
|
* Test voice
|
||||||
|
|
||||||
```
|
```
|
||||||
zk.test_voice()
|
conn.test_voice()
|
||||||
```
|
```
|
||||||
|
|
||||||
* Device Maintenance
|
* Device Maintenance
|
||||||
|
|
||||||
```
|
```
|
||||||
# shutdown connected device
|
# shutdown connected device
|
||||||
zk.power_off()
|
conn.power_off()
|
||||||
# restart connected device
|
# restart connected device
|
||||||
zk.restart()
|
conn.restart()
|
||||||
```
|
```
|
||||||
|
|
||||||
# Related Project
|
# Related Project
|
||||||
|
7
setup.py
7
setup.py
@ -1,18 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pyzk',
|
name='pyzk',
|
||||||
version='0.4',
|
version='0.4',
|
||||||
description='an unofficial library of zksoftware the fingerprint attendance machine.',
|
description='an unofficial library of zksoftware fingerprint device',
|
||||||
url='https://github.com/fananimi/pyzk',
|
url='https://github.com/fananimi/pyzk',
|
||||||
author='Fanani M. Ihsan',
|
author='Fanani M. Ihsan',
|
||||||
author_email='fanani.mi@gmail.com',
|
author_email='fanani.mi@gmail.com',
|
||||||
license='LICENSE.txt',
|
license='LICENSE.txt',
|
||||||
packages=['zk'],
|
packages=['zk'],
|
||||||
keywords=[
|
keywords=[
|
||||||
'zksoftware',
|
|
||||||
'pyzk',
|
|
||||||
'zk',
|
'zk',
|
||||||
|
'pyzk',
|
||||||
|
'zksoftware',
|
||||||
'attendance machine',
|
'attendance machine',
|
||||||
'fingerprint',
|
'fingerprint',
|
||||||
'biometrics',
|
'biometrics',
|
||||||
|
35
test.py
35
test.py
@ -1,26 +1,20 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from zk import ZK, const
|
||||||
|
|
||||||
sys.path.append("zk")
|
sys.path.append("zk")
|
||||||
|
|
||||||
import zk
|
conn = None
|
||||||
from zk import const
|
zk = ZK('192.168.1.10', port=4370, timeout=5)
|
||||||
|
|
||||||
conn = False
|
|
||||||
zk = zk.ZK('192.168.1.201', port=4370, timeout=5)
|
|
||||||
try:
|
try:
|
||||||
print 'Connecting to device ...'
|
print 'Connecting to device ...'
|
||||||
conn = zk.connect()
|
conn = zk.connect()
|
||||||
print 'Disabling device ...'
|
print 'Disabling device ...'
|
||||||
zk.disable_device()
|
conn.disable_device()
|
||||||
print 'Firmware Version: : {}'.format(zk.get_firmware_version())
|
print 'Firmware Version: : {}'.format(conn.get_firmware_version())
|
||||||
# Load test create 2000 users
|
|
||||||
# for i in range(1, 2000+1):
|
|
||||||
# privilege = const.USER_DEFAULT
|
|
||||||
# if i == 1:
|
|
||||||
# privilege = const.USER_ADMIN
|
|
||||||
# print zk.set_user(uid=i, name='user #{}'.format(i), privilege=privilege, password='12345678', group_id='', user_id='{}'.format(i))
|
|
||||||
# print '--- Get User ---'
|
# print '--- Get User ---'
|
||||||
users = zk.get_users()
|
users = conn.get_users()
|
||||||
for user in users:
|
for user in users:
|
||||||
privilege = 'User'
|
privilege = 'User'
|
||||||
if user.privilege == const.USER_ADMIN:
|
if user.privilege == const.USER_ADMIN:
|
||||||
@ -34,18 +28,11 @@ try:
|
|||||||
print ' User ID : {}'.format(user.user_id)
|
print ' User ID : {}'.format(user.user_id)
|
||||||
|
|
||||||
print "Voice Test ..."
|
print "Voice Test ..."
|
||||||
zk.test_voice()
|
conn.test_voice()
|
||||||
# print 'Restarting device ...'
|
|
||||||
# zk.restart()
|
|
||||||
# print 'Turning off device ...'
|
|
||||||
# zk.power_off()
|
|
||||||
print 'Enabling device ...'
|
print 'Enabling device ...'
|
||||||
zk.enable_device()
|
conn.enable_device()
|
||||||
print 'Disconnecting to device ...'
|
|
||||||
zk.disconnect()
|
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "Process terminate : {}".format(e)
|
print "Process terminate : {}".format(e)
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
zk.disconnect()
|
conn.disconnect()
|
||||||
|
@ -6,7 +6,7 @@ class Attendance(object):
|
|||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user_id
|
return '<Attendance>: {}'.format(self.user_id)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Attendance>: {}'.format(self.user_id)
|
return '<Attendance>: {}'.format(self.user_id)
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from socket import AF_INET, SOCK_DGRAM, socket
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
from socket import socket, AF_INET, SOCK_DGRAM
|
|
||||||
|
|
||||||
from zk import const
|
from zk import const
|
||||||
from zk.exception import ZKErrorResponse, ZKNetworkError
|
|
||||||
from zk.attendance import Attendance
|
from zk.attendance import Attendance
|
||||||
|
from zk.exception import ZKErrorResponse, ZKNetworkError
|
||||||
from zk.user import User
|
from zk.user import User
|
||||||
|
|
||||||
|
|
||||||
class ZK(object):
|
class ZK(object):
|
||||||
|
|
||||||
is_connect = False
|
is_connect = False
|
||||||
@ -149,7 +150,7 @@ class ZK(object):
|
|||||||
self.is_connect = True
|
self.is_connect = True
|
||||||
# set the session id
|
# set the session id
|
||||||
self.__sesion_id = unpack('HHHH', self.__data_recv[:8])[2]
|
self.__sesion_id = unpack('HHHH', self.__data_recv[:8])[2]
|
||||||
return True
|
return self
|
||||||
else:
|
else:
|
||||||
raise ZKErrorResponse("Invalid response")
|
raise ZKErrorResponse("Invalid response")
|
||||||
|
|
||||||
@ -493,7 +494,6 @@ class ZK(object):
|
|||||||
|
|
||||||
return attendances
|
return attendances
|
||||||
|
|
||||||
|
|
||||||
def clear_attendance(self):
|
def clear_attendance(self):
|
||||||
'''
|
'''
|
||||||
clear all attendance record
|
clear all attendance record
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
class ZKError(Exception):
|
class ZKError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ZKErrorResponse(ZKError):
|
class ZKErrorResponse(ZKError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ZKNetworkError(ZKError):
|
class ZKNetworkError(ZKError):
|
||||||
pass
|
pass
|
||||||
|
@ -9,8 +9,8 @@ class User(object):
|
|||||||
self.group_id = group_id
|
self.group_id = group_id
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
|
||||||
def __repr__(self):
|
def __str__(self):
|
||||||
return self.name
|
return '<User>: {}'.format(self.name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<User>: {}'.format(self.name)
|
return '<User>: {}'.format(self.name)
|
Loading…
Reference in New Issue
Block a user