zzxlind 2021-10-16 18:42:06

中控考勤,实时获取打卡数据,实时数据上传

import win32com.client
import sys,requests,datetime
import time
import threading
import json
from subprocess import run, PIPE

class EventMask:
    def OnConnected(self):
        print ("OnConnected")
        data = {"OnConnected":"OnConnected"}
        senderror('  OnConnected  '+json.dumps(data),'syszk.log')
        # print(requests.post('',json={"EnrollNumber":"EnrollNumber"}))
        # jiu = json.loads(jj.json())
        # print(jiu["EnrollNumber"])
        
    def OnDisConnected(self):
        print ("OnDisConnected")

    def OnAttTransactionEx(self,EnrollNumber,IsInValid,AttState,VerifyMode,Year,Month,Day,Hour,Minute,Second,WorkCode):
        print("OnAttTransactionEx",EnrollNumber,IsInValid,AttState,VerifyMode,Year,Month,Day,Hour,Minute,Second,WorkCode)
        data = {"EnrollNumber":EnrollNumber,"IsInValid":IsInValid,"AttState":AttState,"VerifyMode":VerifyMode,"Year":Year,"Month":Month,"Day":Day,"Hour":Hour,"Minute":Minute,"Second":Second,"WorkCode":WorkCode}
        senderror("  OnAttTransactionEx  "+json.dumps(data),'syszkAttTransactionEx.log')
		# requests.post('',json=data)
		
    def OnAttTransaction(self,EnrollNumber,IsInValid,AttState,VerifyMethod,Year,Month,Day,Hour,Minute,Second):
        print("OnAttTransaction",EnrollNumber,IsInValid,AttState,VerifyMethod,Year,Month,Day,Hour,Minute,Second)
        
        
class Zkong:
    def connect(self):
        jj = win32com.client.DispatchWithEvents('zkemkeeper.ZKEM.1',EventMask)
        jj.Visible = True
        
        if not jj.Connect_Net("192.168.0.201",4370):
            senderror("  Connect Error")
            jj.Disconnect()
            linkto()

        jj.RegEvent(1,65535)
        while True:
            if not jishi():
                senderror("  web link Error")
                jj.Disconnect()
                linkto()
                break
            time.sleep(60)


def senderror(errcont,myfile='syserror.log'):
    enow=datetime.datetime.now()
    now=enow.strftime('%Y-%m-%d %H:%M:%S')
    errfile=open(myfile,'a')
    errfile.write(now)
    errfile.write(str(errcont))
    errfile.write('\n')
    errfile.close()

def jishi():
    r = run('ping ***.***.22.18',
                        stdout=PIPE,
                        stderr=PIPE,
                        stdin=PIPE,
                        shell=True)
    if r.returncode:
        print('不能正常联网')
        return False
    else:
        print('正常联网')
        return True


def linkto():
    print('111')
    uii = True
    cnt = 1
    while uii:
        r = run('ping ***.***.22.18',
                        stdout=PIPE,
                        stderr=PIPE,
                        stdin=PIPE,
                        shell=True)
        if r.returncode:
            print('relogin 第{}次'.format(cnt))
            senderror('  relogin 第{}次'.format(cnt))
            cnt += 1
            time.sleep(60*1) # 暂停时间
        else:
            uii = False
            print('正常联网')
            jis = Zkong()
            jis.connect()


if __name__ == '__main__':
    list = ""
    jis = Zkong()
    jis.connect()

评论

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.123.4. UTC+08:00, 2024-04-17 22:42
浙ICP备14020137号-1 $访客地图$