From f23bdffaa862456fb527cf0d200b0c560b2eca8e Mon Sep 17 00:00:00 2001 From: "Fanani M. Ihsan" Date: Tue, 30 Apr 2019 21:42:38 +0700 Subject: [PATCH] add more example --- example/clear_data.py | 26 ++++++++++++++++++++++++++ example/set_user.py | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 example/clear_data.py create mode 100644 example/set_user.py diff --git a/example/clear_data.py b/example/clear_data.py new file mode 100644 index 0000000..781e42d --- /dev/null +++ b/example/clear_data.py @@ -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() diff --git a/example/set_user.py b/example/set_user.py new file mode 100644 index 0000000..b48c3f6 --- /dev/null +++ b/example/set_user.py @@ -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()