python考勤系统_Python版中控系统考勤管理

#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‘)

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‘)

print(str(finaluser[i])+‘ ‘,‘12月‘+str(key)+‘日‘+‘ ‘,str(value[0])+‘ ‘,str(value[len(value)-1]), file=fid)

原文:http://www.cnblogs.com/evevil/p/5057368.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值