#coding:utf-8
 
import win32com.client
import sys
import smtplib
import urllib
import os
import string
import chardet
import openpyxl
import time
from datetime import datetime
from collections import Counter

 

zk = win32com.client.Dispatch(\’zkemkeeper.ZKEM.1\’)
if not zk.Connect_Net(\’172.10.14.224\’, 4370):
    print (“Connect Error”)
    sys.exit(1)
 
zk.SSR_GetAllUserInfo(1)
uid = {}
while 1:
    machenum, EnrollNumber, username, other, privilege, dwEnable = zk.SSR_GetAllUserInfo(1)
    if not machenum:
        break
    else:
        if dwEnable:
            uid[EnrollNumber] = str(username.split(u\’\x00\’)[0].encode(\’gbk\’), encoding = “gbk”)

 

#wb=openpyxl.Workbook(optimized_write=True)
#ws=wb.create_sheet()
#for key,value in sorted(uid.items()):
#  ws.append([int(key),value])
#wb.save(filename=\’D:\data.xlsx\’)
#for key,value in sorted(uid.items()):
#    print (key,value)

 

checkin = {}
last_month = time.localtime()[1]-1 or 12
if last_month == 12:
    cur_year = time.localtime()[0]-1
else:
    cur_year = time.localtime()[0]
 
if zk.ReadAllGLogData(1):  #read All checkin data
    while 1:
        dwMachineNumber, dwEnrollNumber, dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkcode = zk.SSR_GetGeneralLogData(1)
        if not dwMachineNumber:
            break
        if cur_year == dwYear and 12 == dwMonth:
            if dwEnrollNumber not in checkin:
                checkin[dwEnrollNumber] = {}
            if dwDay in checkin[dwEnrollNumber]:
                checkin[dwEnrollNumber][dwDay].append(str(dwHour)+\’:\’+str(dwMinute))
            else:
                checkin[dwEnrollNumber][dwDay] = [str(dwHour)+\’:\’+str(dwMinute)]
    
zk.Disconnect()

 

xk = win32com.client.Dispatch(\’zkemkeeper.ZKEM.1\’)
if not xk.Connect_Net(\’172.10.14.237\’, 4370):
    print (“Connect Error”)
    sys.exit(1)
 
xk.SSR_GetAllUserInfo(1)
xid = {}
while 1:
    machenum, EnrollNumber, username, other, privilege, dwEnable = xk.SSR_GetAllUserInfo(1)
    if not machenum:
        break
    else:
        if dwEnable:
            xid[EnrollNumber] = str(username.split(u\’\x00\’)[0].encode(\’gbk\’), encoding = “gbk”)

 

#wb=openpyxl.Workbook(optimized_write=True)
#ws=wb.create_sheet()
#for key,value in sorted(uid.items()):
#  ws.append([int(key),value])
#wb.save(filename=\’D:\data.xlsx\’)
#for key,value in sorted(uid.items()):
#    print (key,value)

 

xheckin = {}
last_month = time.localtime()[1]-1 or 12
if last_month == 12:
    cur_year = time.localtime()[0]-1
else:
    cur_year = time.localtime()[0]
 
if xk.ReadAllGLogData(1):  #read All checkin data
    while 1:
        dwMachineNumber, dwEnrollNumber, dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkcode = xk.SSR_GetGeneralLogData(1)
        if not dwMachineNumber:
            break
        if cur_year == dwYear and 12 == dwMonth:
            if dwEnrollNumber not in xheckin:
                xheckin[dwEnrollNumber] = {}
            if dwDay in xheckin[dwEnrollNumber]:
                xheckin[dwEnrollNumber][dwDay].append(str(dwHour)+\’:\’+str(dwMinute))
            else:
                xheckin[dwEnrollNumber][dwDay] = [str(dwHour)+\’:\’+str(dwMinute)]

 xk.Disconnect()

 

def user(d1, d2): 
    u = dict(d1) 
    u.update(d2) 
    return u
 
def check(d1, d2): 
    c = dict(d1) 
    c.update(d2) 
    return c

 

finaluser=user(uid,xid)
finalcheck=check(checkin,xheckin)
finaluser[\’54\’]=\’54\’
fid = open(“d:\log.xls”, “a”)

 

for i in sorted(finalcheck.keys()):   
    for key,value in sorted(finalcheck[i].items()):
        print(finaluser[i],key,value)
        if datetime.strptime(str(value[0]), \’%H:%M\’) >datetime.strptime(\’14:00\’, \’%H:%M\’):
            print(str(finaluser[i])+\’ \’,\’12月\’+str(key)+\’日\’+\’ \’,\’未打卡\’+\’ \’,str(value[len(value)-1]), file=fid)
        if datetime.strptime(str(value[len(value)-1]), \’%H:%M\’) <datetime.strptime(\’14:00\’, \’%H:%M\’):
            print(str(finaluser[i])+\’ \’,\’12月\’+str(key)+\’日\’+\’ \’,str(value[0])+\’ \’,\’未打卡\’, file=fid)
        if datetime.strptime(str(value[len(value)-1]), \’%H:%M\’) >datetime.strptime(\’14:00\’, \’%H:%M\’) and datetime.strptime(str(value[0]), \’%H:%M\’) <datetime.strptime(\’14:00\’, \’%H:%M\’):
            print(str(finaluser[i])+\’ \’,\’12月\’+str(key)+\’日\’+\’ \’,str(value[0])+\’ \’,str(value[len(value)-1]), file=fid)

 

版权声明:本文为evevil原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/evevil/p/5057368.html