forked from frappe/biometric-attendance-sync-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoc.py
executable file
·37 lines (32 loc) · 1.21 KB
/
poc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from zk import ZK, const
import json
import datetime
# ip="192.168.1.201"
# port=4370
ip="0.tcp.in.ngrok.io"
port=13296
timeout=30
# Sample Attendance Logs [{'punch': 255, 'user_id': '22', 'uid': 12349, 'status': 1, 'timestamp': datetime.datetime(2019, 2, 26, 20, 31, 29)},{'punch': 255, 'user_id': '7', 'uid': 7, 'status': 1, 'timestamp': datetime.datetime(2019, 2, 26, 20, 31, 36)}]
zk = ZK(ip, port=port, timeout=timeout)
print("Connecting to device... {}:{}".format(ip, port))
conn = None
attendances = []
try:
conn = zk.connect()
x = conn.disable_device()
# device is disabled when fetching data
print("\t".join((ip, "Device Disable Attempted. Result:", str(x))))
attendances = conn.get_attendance()
print("\t".join((ip, "Attendances Fetched:", str(len(attendances)))))
print(attendances[0:10])
# map attendances to a dict
f = open("data.json", "w")
f.write(json.dumps(list(map(lambda x: x.__dict__, attendances)), default=datetime.datetime.timestamp))
f.close()
except:
print(str(ip)+' exception when fetching from device...')
raise Exception('Device fetch failed.')
finally:
if conn:
conn.disconnect()
# return list(map(lambda x: x.__dict__, attendances))