Beispiel #1
0
def disconnect_device():
    zk = ZK('192.168.1.220', port=4370, timeout=5)
    try:
        print('Disconnecting to device ...')
        zk.disconnect()
    except ZKErrorConnection as e:
        return "instance are not connected."
    return "Disconnected"
Beispiel #2
0
    exnd_dict = {}
    attend_list = []
    headers = login()

    for data in att_data:
        uid = int(data.uid)
        if int(data.uid) in users_map.keys():
            attnd_dat = {}
            #print "User %s(%s,%s) punched at %s, %s, %s " %(users_map[uid].name, str(uid), str(users_map[uid].card),
            #str(data.timestamp), str(data.punch), str(data.status))
            attnd_dat["Name"] = users_map[uid].name
            attnd_dat["uId"] = str(uid)
            attnd_dat["cardNum"] = str(users_map[uid].card)
            attnd_dat["time"] = str(data.timestamp)
            getdat = str(data.timestamp)
            date = datetime.strptime(getdat,
                                     '%Y-%m-%d %H:%M:%S').strftime('%d-%m-%Y')
            attnd_dat["Date"] = date
            attend_list.append(attnd_dat)
        else:
            print "unknown user with  uid=%s punched at %s" % (
                uid, str(data.timestamp))
        #attnd_json(attnd_dat, headers)
    #print json.dumps(attend_list)
    dicval = json.dumps(attend_list)
    with open("schdata.json", "w") as intf:
        intf.write(dicval)
    daily_attendance(dicval, headers)
    zk.disconnect()
Beispiel #3
0
class ZKUtil(object):
    def __init__(self, logger, ip, port=4370):

        self.log = logger
        self.sep = ','

        self.zk_sttg = None
        self.zk_ip = ip
        self.zk_port = port
        self.zk_conn = None
        self.timeout = 5
        self.passwd = 0
        self.fc_udp = False
        self.om_png = False

    def _zk_connect(self):

        ret = 1

        try:
            self.zk_conn = ZK(self.zk_ip, self.zk_port, self.timeout,
                              self.passwd, self.fc_udp, self.om_png)

            self.zk_conn = self.zk_conn.connect()
            self.log.info(f" connected to machine, ip {self.zk_ip}")
            ret = 0
        except Exception as e:
            self.log.error(
                f"Except error to connect -> {self.zk_ip}, detail -> {e}")
            self.log.error(f"Except zk error, {sys.exc_info()}")
        finally:
            return ret

    def _zk_is_connected(self):

        try:
            if self.zk_conn:
                return True
            else:
                self.log.error(f"zk conn is {self.zk_conn}")
                return False
        except Exception as e:
            self.log.info(f"Except -> {e} ")
            self.log.error(f" Except {sys.exc_info()}")

    def _zk_disconnect(self):

        ret = 1

        try:
            if self._zk_is_connected():
                self.zk_conn.disconnect()
                self.log.info(
                    f" disconnect from fingerprint, ip => {self.zk_ip}")
                ret = 0
        except Exception as e:
            self.log.info(f"Except -> {e} ")
            self.log.error(f" Except {sys.exc_info()}")
        finally:
            return ret

    def _zk_firmware(self):
        ret = 1

        try:
            if self._zk_is_connected():
                ret = self.zk_conn.get_firmware_version()
        except Exception as e:
            self.log.error(f" Except error , detail -> {e}")
            self.log.error(f" Except {sys.exc_info()}")
        finally:
            return ret

    def _zk_live_attendance(self):

        ret = 1

        try:
            if self._zk_is_connected():
                ret = self.zk_conn.get_firmware_version()
        except Exception as e:
            self.log.error(f" Except error , detail -> {e}")
            self.log.error(f" Except {sys.exc_info()}")
        finally:
            return ret

    def _zk_get_attendance(self):

        ret = []

        tmp = {
            '1': "47714351",
            '2': "46373211",
            '4': "47598830",
            '5': "45448470",
            '6': "46027680"
        }

        try:
            if self._zk_is_connected():
                ret = self.zk_conn.get_attendance()

                if len(ret) == 0:
                    self.log.error(f"attendance is len = 0, {attendance}")

        except Exception as e:
            self.log.error(f" Except error , detail -> {e}")
            self.log.error(f" Except {sys.exc_info()}")
        finally:
            return ret

    def _zk_clear_attendance(self):

        ret = 1

        try:
            if self._zk_is_connected():
                self.zk_conn.clear_attendance()
                ret = 0
        except Exception as e:
            self.log.error(f"Except error, detail -> {e}")
            self.log.error(f"Except {sys.exc_info()}")
        finally:
            return ret

    def _zk_reboot_machine(self):

        ret = 1

        try:
            if self._zk_is_connected():
                self.zk_conn.restart()
                ret = 0
        except Exception as e:
            self.log.error(f" Except error , detail -> {e}")
            self.log.error(f" Except {sys.exc_info()}")
        finally:
            return ret