Initial test
This commit is contained in:
75
setUser_.py
Normal file
75
setUser_.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
import csv
|
||||
|
||||
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__)
|
||||
|
||||
mesin_absen = [
|
||||
{ "lokasi" : "Painting In", "ip": "10.35.14.14" },
|
||||
{ "lokasi" : "Painting Out" , "ip": "10.35.14.13" },
|
||||
{ "lokasi" : "Injection In", "ip": "10.35.7.10"},
|
||||
{ "lokasi" : "Injection Out", "ip": "10.35.7.11"},
|
||||
{ "lokasi" : "Office", "ip": "10.35.14.10"},
|
||||
{ "lokasi" : "Hotpress in", "ip":"10.35.14.15"},
|
||||
{ "lokasi" : "Hotpress out", "ip":"10.35.14.16"},
|
||||
{ "lokasi" : "KIIC", "ip": "10.45.7.2"},
|
||||
{ "lokasi" : "Injection 2", "ip":"10.35.7.12"},
|
||||
]
|
||||
|
||||
#print(mesin_absen[0]['lokasi'])
|
||||
|
||||
def koneksi_mesin(ipaddress):
|
||||
conn = None
|
||||
zk = ZK(ipaddress, port=4370, verbose=True)
|
||||
return zk
|
||||
print("Koneksi tersambung")
|
||||
|
||||
def input_karyawan(zk, uid=10, name="Aries P. Wibowo", privilege=const.USER_DEFAULT, password='', user_id="4249"):
|
||||
try:
|
||||
conn = zk.connect()
|
||||
conn.set_user(uid=uid, name=name, privilege=privilege, password=password, user_id=user_id)#(uid=uid, name=name, privilege=const.USER_DEFAULT, password='', user_id=user_id)
|
||||
#conn.test_voice(index=0)
|
||||
except Exception as e:
|
||||
print ("Process terminate : {}".format(e))
|
||||
finally:
|
||||
if conn:
|
||||
conn.disconnect()
|
||||
|
||||
def importCSV():
|
||||
#Import user from csv
|
||||
with open('user_dump1.csv', mode='r') as file:
|
||||
reader = csv.reader(file, delimiter=',')
|
||||
|
||||
# Skip the header row
|
||||
next(reader)
|
||||
|
||||
# Specify column indices to read
|
||||
column_indices = [1, 4] # Example: reads the first and third columns
|
||||
|
||||
for row in reader:
|
||||
selected_columns = [row[i] for i in column_indices]
|
||||
print(selected_columns)
|
||||
#uid = row[0]
|
||||
name = row[1]
|
||||
user_id = row[4]
|
||||
|
||||
try:
|
||||
conn = zk.connect()
|
||||
conn.set_user(uid=None, name=name, privilege=const.USER_DEFAULT, password='', user_id=user_id)#(uid=uid, name=name, privilege=const.USER_DEFAULT, password='', user_id=user_id)
|
||||
#conn.test_voice(index=0)
|
||||
except Exception as e:
|
||||
print ("Process terminate : {}".format(e))
|
||||
finally:
|
||||
if conn:
|
||||
conn.disconnect()
|
||||
|
||||
koneksi = koneksi_mesin("10.35.7.13")
|
||||
print(koneksi)
|
||||
input_karyawan(koneksi)
|
||||
Reference in New Issue
Block a user