add more example

This commit is contained in:
Fanani M. Ihsan 2019-04-30 21:42:38 +07:00
parent cd81782509
commit f23bdffaa8
2 changed files with 48 additions and 0 deletions

26
example/clear_data.py Normal file
View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK
conn = None
zk = ZK('192.168.2.201', port=4370)
try:
conn = zk.connect()
choices = raw_input('Are you sure want to delete all data? [Y/N]: ')
if choices == 'Y':
print ("Clear all data...")
conn.clear_data()
else:
print ("Clear all data canceled !")
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()

22
example/set_user.py Normal file
View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
import os
import sys
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(CWD)
sys.path.append(ROOT_DIR)
from zk import ZK, const
import zk
print (zk.__file__)
conn = None
zk = ZK('192.168.2.201', port=4370, verbose=True)
try:
conn = zk.connect()
conn.set_user(uid=1, name='John Doe', privilege=const.USER_DEFAULT, password='12345678', user_id='1')
except Exception as e:
print ("Process terminate : {}".format(e))
finally:
if conn:
conn.disconnect()